121 |
|
} |
122 |
|
|
123 |
|
/** A constant to clarify calls to checking methods below. */ |
124 |
< |
final static Thread[] NO_THREADS = new Thread[0]; |
124 |
> |
static final Thread[] NO_THREADS = new Thread[0]; |
125 |
|
|
126 |
|
/** |
127 |
|
* Spin-waits until sync.isQueued(t) becomes true. |
947 |
|
} |
948 |
|
|
949 |
|
/** |
950 |
< |
* awaitUninterruptibly doesn't abort on interrupt |
950 |
> |
* awaitUninterruptibly is uninterruptible |
951 |
|
*/ |
952 |
|
public void testAwaitUninterruptibly() { |
953 |
|
final Mutex sync = new Mutex(); |
954 |
|
final ConditionObject c = sync.newCondition(); |
955 |
< |
final BooleanLatch acquired = new BooleanLatch(); |
955 |
> |
final BooleanLatch pleaseInterrupt = new BooleanLatch(); |
956 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
957 |
|
public void realRun() { |
958 |
|
sync.acquire(); |
959 |
< |
assertTrue(acquired.releaseShared(0)); |
959 |
> |
assertTrue(pleaseInterrupt.releaseShared(0)); |
960 |
|
c.awaitUninterruptibly(); |
961 |
|
assertTrue(Thread.interrupted()); |
962 |
|
assertHasWaitersLocked(sync, c, NO_THREADS); |
963 |
|
sync.release(); |
964 |
|
}}); |
965 |
|
|
966 |
< |
acquired.acquireShared(0); |
966 |
> |
pleaseInterrupt.acquireShared(0); |
967 |
|
sync.acquire(); |
968 |
|
assertHasWaitersLocked(sync, c, t); |
969 |
|
sync.release(); |
990 |
|
public void testInterruptible(final AwaitMethod awaitMethod) { |
991 |
|
final Mutex sync = new Mutex(); |
992 |
|
final ConditionObject c = sync.newCondition(); |
993 |
< |
final BooleanLatch acquired = new BooleanLatch(); |
993 |
> |
final BooleanLatch pleaseInterrupt = new BooleanLatch(); |
994 |
|
Thread t = newStartedThread(new CheckedInterruptedRunnable() { |
995 |
|
public void realRun() throws InterruptedException { |
996 |
|
sync.acquire(); |
997 |
< |
assertTrue(acquired.releaseShared(0)); |
997 |
> |
assertTrue(pleaseInterrupt.releaseShared(0)); |
998 |
|
await(c, awaitMethod); |
999 |
|
}}); |
1000 |
|
|
1001 |
< |
acquired.acquireShared(0); |
1001 |
> |
pleaseInterrupt.acquireShared(0); |
1002 |
|
t.interrupt(); |
1003 |
|
awaitTermination(t); |
1004 |
|
} |