19 |
|
import junit.framework.Test; |
20 |
|
import junit.framework.TestSuite; |
21 |
|
|
22 |
+ |
@SuppressWarnings("WaitNotInLoop") // we implement spurious-wakeup freedom |
23 |
|
public class AbstractQueuedSynchronizerTest extends JSR166TestCase { |
24 |
|
public static void main(String[] args) { |
25 |
|
main(suite(), args); |
969 |
|
*/ |
970 |
|
public void testAwaitUninterruptibly() { |
971 |
|
final Mutex sync = new Mutex(); |
972 |
< |
final ConditionObject c = sync.newCondition(); |
972 |
> |
final ConditionObject condition = sync.newCondition(); |
973 |
|
final BooleanLatch pleaseInterrupt = new BooleanLatch(); |
974 |
|
Thread t = newStartedThread(new CheckedRunnable() { |
975 |
|
public void realRun() { |
976 |
|
sync.acquire(); |
977 |
|
assertTrue(pleaseInterrupt.releaseShared(0)); |
978 |
< |
c.awaitUninterruptibly(); |
978 |
> |
condition.awaitUninterruptibly(); |
979 |
|
assertTrue(Thread.interrupted()); |
980 |
< |
assertHasWaitersLocked(sync, c, NO_THREADS); |
980 |
> |
assertHasWaitersLocked(sync, condition, NO_THREADS); |
981 |
|
sync.release(); |
982 |
|
}}); |
983 |
|
|
984 |
|
pleaseInterrupt.acquireShared(0); |
985 |
|
sync.acquire(); |
986 |
< |
assertHasWaitersLocked(sync, c, t); |
986 |
> |
assertHasWaitersLocked(sync, condition, t); |
987 |
|
sync.release(); |
988 |
|
t.interrupt(); |
989 |
< |
assertHasWaitersUnlocked(sync, c, t); |
990 |
< |
assertThreadStaysAlive(t); |
989 |
> |
assertHasWaitersUnlocked(sync, condition, t); |
990 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
991 |
|
sync.acquire(); |
992 |
< |
assertHasWaitersLocked(sync, c, t); |
992 |
> |
assertHasWaitersLocked(sync, condition, t); |
993 |
|
assertHasExclusiveQueuedThreads(sync, NO_THREADS); |
994 |
< |
c.signal(); |
995 |
< |
assertHasWaitersLocked(sync, c, NO_THREADS); |
994 |
> |
condition.signal(); |
995 |
> |
assertHasWaitersLocked(sync, condition, NO_THREADS); |
996 |
|
assertHasExclusiveQueuedThreads(sync, t); |
997 |
|
sync.release(); |
998 |
|
awaitTermination(t); |
1135 |
|
|
1136 |
|
waitForQueuedThread(l, t); |
1137 |
|
assertFalse(l.isSignalled()); |
1138 |
< |
assertThreadStaysAlive(t); |
1138 |
> |
assertThreadBlocks(t, Thread.State.WAITING); |
1139 |
|
assertHasSharedQueuedThreads(l, t); |
1140 |
|
assertTrue(l.releaseShared(0)); |
1141 |
|
assertTrue(l.isSignalled()); |
1160 |
|
|
1161 |
|
waitForQueuedThread(l, t); |
1162 |
|
assertFalse(l.isSignalled()); |
1163 |
< |
assertThreadStaysAlive(t); |
1163 |
> |
assertThreadBlocks(t, Thread.State.TIMED_WAITING); |
1164 |
|
assertTrue(l.releaseShared(0)); |
1165 |
|
assertTrue(l.isSignalled()); |
1166 |
|
awaitTermination(t); |