Lines Matching refs:sync

112         final Mutex sync;  field in AbstractQueuedLongSynchronizerTest.InterruptibleSyncRunnable
113 InterruptibleSyncRunnable(Mutex sync) { this.sync = sync; } in InterruptibleSyncRunnable() argument
115 sync.acquireInterruptibly(); in realRun()
124 final Mutex sync; field in AbstractQueuedLongSynchronizerTest.InterruptedSyncRunnable
125 InterruptedSyncRunnable(Mutex sync) { this.sync = sync; } in InterruptedSyncRunnable() argument
127 sync.acquireInterruptibly(); in realRun()
137 void waitForQueuedThread(AbstractQueuedLongSynchronizer sync, in waitForQueuedThread() argument
140 while (!sync.isQueued(t)) { in waitForQueuedThread()
151 void assertHasQueuedThreads(AbstractQueuedLongSynchronizer sync, in assertHasQueuedThreads() argument
153 Collection<Thread> actual = sync.getQueuedThreads(); in assertHasQueuedThreads()
154 assertEquals(expected.length > 0, sync.hasQueuedThreads()); in assertHasQueuedThreads()
155 assertEquals(expected.length, sync.getQueueLength()); in assertHasQueuedThreads()
165 void assertHasExclusiveQueuedThreads(AbstractQueuedLongSynchronizer sync, in assertHasExclusiveQueuedThreads() argument
167 assertHasQueuedThreads(sync, expected); in assertHasExclusiveQueuedThreads()
168 assertEquals(new HashSet<Thread>(sync.getExclusiveQueuedThreads()), in assertHasExclusiveQueuedThreads()
169 new HashSet<Thread>(sync.getQueuedThreads())); in assertHasExclusiveQueuedThreads()
170 assertEquals(0, sync.getSharedQueuedThreads().size()); in assertHasExclusiveQueuedThreads()
171 assertTrue(sync.getSharedQueuedThreads().isEmpty()); in assertHasExclusiveQueuedThreads()
177 void assertHasSharedQueuedThreads(AbstractQueuedLongSynchronizer sync, in assertHasSharedQueuedThreads() argument
179 assertHasQueuedThreads(sync, expected); in assertHasSharedQueuedThreads()
180 assertEquals(new HashSet<Thread>(sync.getSharedQueuedThreads()), in assertHasSharedQueuedThreads()
181 new HashSet<Thread>(sync.getQueuedThreads())); in assertHasSharedQueuedThreads()
182 assertEquals(0, sync.getExclusiveQueuedThreads().size()); in assertHasSharedQueuedThreads()
183 assertTrue(sync.getExclusiveQueuedThreads().isEmpty()); in assertHasSharedQueuedThreads()
190 void assertHasWaitersUnlocked(Mutex sync, ConditionObject c, in assertHasWaitersUnlocked() argument
192 sync.acquire(); in assertHasWaitersUnlocked()
193 assertHasWaitersLocked(sync, c, threads); in assertHasWaitersUnlocked()
194 sync.release(); in assertHasWaitersUnlocked()
200 void assertHasWaitersLocked(Mutex sync, ConditionObject c, in assertHasWaitersLocked() argument
202 assertEquals(threads.length > 0, sync.hasWaiters(c)); in assertHasWaitersLocked()
203 assertEquals(threads.length, sync.getWaitQueueLength(c)); in assertHasWaitersLocked()
204 assertEquals(threads.length == 0, sync.getWaitingThreads(c).isEmpty()); in assertHasWaitersLocked()
205 assertEquals(threads.length, sync.getWaitingThreads(c).size()); in assertHasWaitersLocked()
206 assertEquals(new HashSet<Thread>(sync.getWaitingThreads(c)), in assertHasWaitersLocked()
277 Mutex sync = new Mutex(); in testIsHeldExclusively() local
278 assertFalse(sync.isHeldExclusively()); in testIsHeldExclusively()
285 Mutex sync = new Mutex(); in testAcquire() local
286 sync.acquire(); in testAcquire()
287 assertTrue(sync.isHeldExclusively()); in testAcquire()
288 sync.release(); in testAcquire()
289 assertFalse(sync.isHeldExclusively()); in testAcquire()
296 Mutex sync = new Mutex(); in testTryAcquire() local
297 assertTrue(sync.tryAcquire()); in testTryAcquire()
298 assertTrue(sync.isHeldExclusively()); in testTryAcquire()
299 sync.release(); in testTryAcquire()
300 assertFalse(sync.isHeldExclusively()); in testTryAcquire()
307 final Mutex sync = new Mutex(); in testHasQueuedThreads() local
308 assertFalse(sync.hasQueuedThreads()); in testHasQueuedThreads()
309 sync.acquire(); in testHasQueuedThreads()
310 Thread t1 = newStartedThread(new InterruptedSyncRunnable(sync)); in testHasQueuedThreads()
311 waitForQueuedThread(sync, t1); in testHasQueuedThreads()
312 assertTrue(sync.hasQueuedThreads()); in testHasQueuedThreads()
313 Thread t2 = newStartedThread(new InterruptibleSyncRunnable(sync)); in testHasQueuedThreads()
314 waitForQueuedThread(sync, t2); in testHasQueuedThreads()
315 assertTrue(sync.hasQueuedThreads()); in testHasQueuedThreads()
318 assertTrue(sync.hasQueuedThreads()); in testHasQueuedThreads()
319 sync.release(); in testHasQueuedThreads()
321 assertFalse(sync.hasQueuedThreads()); in testHasQueuedThreads()
328 final Mutex sync = new Mutex(); in testIsQueuedNPE() local
330 sync.isQueued(null); in testIsQueuedNPE()
339 final Mutex sync = new Mutex(); in testIsQueued() local
340 Thread t1 = new Thread(new InterruptedSyncRunnable(sync)); in testIsQueued()
341 Thread t2 = new Thread(new InterruptibleSyncRunnable(sync)); in testIsQueued()
342 assertFalse(sync.isQueued(t1)); in testIsQueued()
343 assertFalse(sync.isQueued(t2)); in testIsQueued()
344 sync.acquire(); in testIsQueued()
346 waitForQueuedThread(sync, t1); in testIsQueued()
347 assertTrue(sync.isQueued(t1)); in testIsQueued()
348 assertFalse(sync.isQueued(t2)); in testIsQueued()
350 waitForQueuedThread(sync, t2); in testIsQueued()
351 assertTrue(sync.isQueued(t1)); in testIsQueued()
352 assertTrue(sync.isQueued(t2)); in testIsQueued()
355 assertFalse(sync.isQueued(t1)); in testIsQueued()
356 assertTrue(sync.isQueued(t2)); in testIsQueued()
357 sync.release(); in testIsQueued()
359 assertFalse(sync.isQueued(t1)); in testIsQueued()
360 assertFalse(sync.isQueued(t2)); in testIsQueued()
367 final Mutex sync = new Mutex(); in testGetFirstQueuedThread() local
368 assertNull(sync.getFirstQueuedThread()); in testGetFirstQueuedThread()
369 sync.acquire(); in testGetFirstQueuedThread()
370 Thread t1 = newStartedThread(new InterruptedSyncRunnable(sync)); in testGetFirstQueuedThread()
371 waitForQueuedThread(sync, t1); in testGetFirstQueuedThread()
372 assertEquals(t1, sync.getFirstQueuedThread()); in testGetFirstQueuedThread()
373 Thread t2 = newStartedThread(new InterruptibleSyncRunnable(sync)); in testGetFirstQueuedThread()
374 waitForQueuedThread(sync, t2); in testGetFirstQueuedThread()
375 assertEquals(t1, sync.getFirstQueuedThread()); in testGetFirstQueuedThread()
378 assertEquals(t2, sync.getFirstQueuedThread()); in testGetFirstQueuedThread()
379 sync.release(); in testGetFirstQueuedThread()
381 assertNull(sync.getFirstQueuedThread()); in testGetFirstQueuedThread()
388 final Mutex sync = new Mutex(); in testHasContended() local
389 assertFalse(sync.hasContended()); in testHasContended()
390 sync.acquire(); in testHasContended()
391 assertFalse(sync.hasContended()); in testHasContended()
392 Thread t1 = newStartedThread(new InterruptedSyncRunnable(sync)); in testHasContended()
393 waitForQueuedThread(sync, t1); in testHasContended()
394 assertTrue(sync.hasContended()); in testHasContended()
395 Thread t2 = newStartedThread(new InterruptibleSyncRunnable(sync)); in testHasContended()
396 waitForQueuedThread(sync, t2); in testHasContended()
397 assertTrue(sync.hasContended()); in testHasContended()
400 assertTrue(sync.hasContended()); in testHasContended()
401 sync.release(); in testHasContended()
403 assertTrue(sync.hasContended()); in testHasContended()
410 final Mutex sync = new Mutex(); in testGetQueuedThreads() local
411 Thread t1 = new Thread(new InterruptedSyncRunnable(sync)); in testGetQueuedThreads()
412 Thread t2 = new Thread(new InterruptibleSyncRunnable(sync)); in testGetQueuedThreads()
413 assertHasExclusiveQueuedThreads(sync, NO_THREADS); in testGetQueuedThreads()
414 sync.acquire(); in testGetQueuedThreads()
415 assertHasExclusiveQueuedThreads(sync, NO_THREADS); in testGetQueuedThreads()
417 waitForQueuedThread(sync, t1); in testGetQueuedThreads()
418 assertHasExclusiveQueuedThreads(sync, t1); in testGetQueuedThreads()
419 assertTrue(sync.getQueuedThreads().contains(t1)); in testGetQueuedThreads()
420 assertFalse(sync.getQueuedThreads().contains(t2)); in testGetQueuedThreads()
422 waitForQueuedThread(sync, t2); in testGetQueuedThreads()
423 assertHasExclusiveQueuedThreads(sync, t1, t2); in testGetQueuedThreads()
424 assertTrue(sync.getQueuedThreads().contains(t1)); in testGetQueuedThreads()
425 assertTrue(sync.getQueuedThreads().contains(t2)); in testGetQueuedThreads()
428 assertHasExclusiveQueuedThreads(sync, t2); in testGetQueuedThreads()
429 sync.release(); in testGetQueuedThreads()
431 assertHasExclusiveQueuedThreads(sync, NO_THREADS); in testGetQueuedThreads()
438 final Mutex sync = new Mutex(); in testGetExclusiveQueuedThreads() local
439 Thread t1 = new Thread(new InterruptedSyncRunnable(sync)); in testGetExclusiveQueuedThreads()
440 Thread t2 = new Thread(new InterruptibleSyncRunnable(sync)); in testGetExclusiveQueuedThreads()
441 assertHasExclusiveQueuedThreads(sync, NO_THREADS); in testGetExclusiveQueuedThreads()
442 sync.acquire(); in testGetExclusiveQueuedThreads()
443 assertHasExclusiveQueuedThreads(sync, NO_THREADS); in testGetExclusiveQueuedThreads()
445 waitForQueuedThread(sync, t1); in testGetExclusiveQueuedThreads()
446 assertHasExclusiveQueuedThreads(sync, t1); in testGetExclusiveQueuedThreads()
447 assertTrue(sync.getExclusiveQueuedThreads().contains(t1)); in testGetExclusiveQueuedThreads()
448 assertFalse(sync.getExclusiveQueuedThreads().contains(t2)); in testGetExclusiveQueuedThreads()
450 waitForQueuedThread(sync, t2); in testGetExclusiveQueuedThreads()
451 assertHasExclusiveQueuedThreads(sync, t1, t2); in testGetExclusiveQueuedThreads()
452 assertTrue(sync.getExclusiveQueuedThreads().contains(t1)); in testGetExclusiveQueuedThreads()
453 assertTrue(sync.getExclusiveQueuedThreads().contains(t2)); in testGetExclusiveQueuedThreads()
456 assertHasExclusiveQueuedThreads(sync, t2); in testGetExclusiveQueuedThreads()
457 sync.release(); in testGetExclusiveQueuedThreads()
459 assertHasExclusiveQueuedThreads(sync, NO_THREADS); in testGetExclusiveQueuedThreads()
466 final Mutex sync = new Mutex(); in testGetSharedQueuedThreads_Exclusive() local
467 assertTrue(sync.getSharedQueuedThreads().isEmpty()); in testGetSharedQueuedThreads_Exclusive()
468 sync.acquire(); in testGetSharedQueuedThreads_Exclusive()
469 assertTrue(sync.getSharedQueuedThreads().isEmpty()); in testGetSharedQueuedThreads_Exclusive()
470 Thread t1 = newStartedThread(new InterruptedSyncRunnable(sync)); in testGetSharedQueuedThreads_Exclusive()
471 waitForQueuedThread(sync, t1); in testGetSharedQueuedThreads_Exclusive()
472 assertTrue(sync.getSharedQueuedThreads().isEmpty()); in testGetSharedQueuedThreads_Exclusive()
473 Thread t2 = newStartedThread(new InterruptibleSyncRunnable(sync)); in testGetSharedQueuedThreads_Exclusive()
474 waitForQueuedThread(sync, t2); in testGetSharedQueuedThreads_Exclusive()
475 assertTrue(sync.getSharedQueuedThreads().isEmpty()); in testGetSharedQueuedThreads_Exclusive()
478 assertTrue(sync.getSharedQueuedThreads().isEmpty()); in testGetSharedQueuedThreads_Exclusive()
479 sync.release(); in testGetSharedQueuedThreads_Exclusive()
481 assertTrue(sync.getSharedQueuedThreads().isEmpty()); in testGetSharedQueuedThreads_Exclusive()
514 final Mutex sync = new Mutex(); in testTryAcquireNanos_Interruptible() local
515 sync.acquire(); in testTryAcquireNanos_Interruptible()
518 sync.tryAcquireNanos(MILLISECONDS.toNanos(2 * LONG_DELAY_MS)); in testTryAcquireNanos_Interruptible()
521 waitForQueuedThread(sync, t); in testTryAcquireNanos_Interruptible()
530 final Mutex sync = new Mutex(); in testTryAcquireWhenSynced() local
531 sync.acquire(); in testTryAcquireWhenSynced()
534 assertFalse(sync.tryAcquire()); in testTryAcquireWhenSynced()
538 sync.release(); in testTryAcquireWhenSynced()
545 final Mutex sync = new Mutex(); in testAcquireNanos_Timeout() local
546 sync.acquire(); in testAcquireNanos_Timeout()
551 assertFalse(sync.tryAcquireNanos(nanos)); in testAcquireNanos_Timeout()
556 sync.release(); in testAcquireNanos_Timeout()
563 final Mutex sync = new Mutex(); in testGetState() local
564 sync.acquire(); in testGetState()
565 assertTrue(sync.isHeldExclusively()); in testGetState()
566 sync.release(); in testGetState()
567 assertFalse(sync.isHeldExclusively()); in testGetState()
573 sync.acquire(); in testGetState()
576 sync.release(); in testGetState()
580 assertTrue(sync.isHeldExclusively()); in testGetState()
583 assertFalse(sync.isHeldExclusively()); in testGetState()
590 final Mutex sync = new Mutex(); in testAcquireInterruptibly() local
592 sync.acquireInterruptibly(); in testAcquireInterruptibly()
596 sync.acquireInterruptibly(); in testAcquireInterruptibly()
600 waitForQueuedThread(sync, t); in testAcquireInterruptibly()
603 assertTrue(sync.isHeldExclusively()); in testAcquireInterruptibly()
610 final Mutex sync = new Mutex(); in testOwns() local
611 final ConditionObject c = sync.newCondition(); in testOwns()
613 assertTrue(sync.owns(c)); in testOwns()
621 final Mutex sync = new Mutex(); in testAwait_IMSE() local
622 final ConditionObject c = sync.newCondition(); in testAwait_IMSE()
638 final Mutex sync = new Mutex();
639 final ConditionObject c = sync.newCondition();
644 assertHasWaitersUnlocked(sync, c, NO_THREADS);
651 final Mutex sync = new Mutex();
652 final ConditionObject c = sync.newCondition();
666 final Mutex sync = new Mutex();
667 final ConditionObject c = sync.newCondition();
668 sync.acquire();
670 sync.release();
681 final Mutex sync = new Mutex();
682 final ConditionObject c = sync.newCondition();
686 sync.acquire();
689 sync.release();
693 sync.acquire();
694 assertHasWaitersLocked(sync, c, t);
695 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
697 assertHasWaitersLocked(sync, c, NO_THREADS);
698 assertHasExclusiveQueuedThreads(sync, t);
699 sync.release();
707 final Mutex sync = new Mutex();
709 sync.hasWaiters(null);
718 final Mutex sync = new Mutex();
720 sync.getWaitQueueLength(null);
729 final Mutex sync = new Mutex();
731 sync.getWaitingThreads(null);
740 final Mutex sync = new Mutex();
741 final ConditionObject c = sync.newCondition();
747 assertHasWaitersUnlocked(sync, c, NO_THREADS);
754 final Mutex sync = new Mutex();
755 final ConditionObject c = sync.newCondition();
757 sync.hasWaiters(c);
760 assertHasWaitersUnlocked(sync, c, NO_THREADS);
767 final Mutex sync = new Mutex();
768 final ConditionObject c = sync.newCondition();
774 assertHasWaitersUnlocked(sync, c, NO_THREADS);
781 final Mutex sync = new Mutex();
782 final ConditionObject c = sync.newCondition();
784 sync.getWaitQueueLength(c);
787 assertHasWaitersUnlocked(sync, c, NO_THREADS);
794 final Mutex sync = new Mutex();
795 final ConditionObject c = sync.newCondition();
801 assertHasWaitersUnlocked(sync, c, NO_THREADS);
808 final Mutex sync = new Mutex();
809 final ConditionObject c = sync.newCondition();
811 sync.getWaitingThreads(c);
814 assertHasWaitersUnlocked(sync, c, NO_THREADS);
821 final Mutex sync = new Mutex();
822 final ConditionObject c = sync.newCondition();
826 sync.acquire();
827 assertHasWaitersLocked(sync, c, NO_THREADS);
828 assertFalse(sync.hasWaiters(c));
831 sync.release();
835 sync.acquire();
836 assertHasWaitersLocked(sync, c, t);
837 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
838 assertTrue(sync.hasWaiters(c));
840 assertHasWaitersLocked(sync, c, NO_THREADS);
841 assertHasExclusiveQueuedThreads(sync, t);
842 assertFalse(sync.hasWaiters(c));
843 sync.release();
846 assertHasWaitersUnlocked(sync, c, NO_THREADS);
853 final Mutex sync = new Mutex();
854 final ConditionObject c = sync.newCondition();
859 sync.acquire();
860 assertHasWaitersLocked(sync, c, NO_THREADS);
861 assertEquals(0, sync.getWaitQueueLength(c));
864 sync.release();
867 sync.acquire();
868 assertHasWaitersLocked(sync, c, t1);
869 assertEquals(1, sync.getWaitQueueLength(c));
870 sync.release();
874 sync.acquire();
875 assertHasWaitersLocked(sync, c, t1);
876 assertEquals(1, sync.getWaitQueueLength(c));
879 sync.release();
882 sync.acquire();
883 assertHasWaitersLocked(sync, c, t1, t2);
884 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
885 assertEquals(2, sync.getWaitQueueLength(c));
887 assertHasWaitersLocked(sync, c, NO_THREADS);
888 assertHasExclusiveQueuedThreads(sync, t1, t2);
889 assertEquals(0, sync.getWaitQueueLength(c));
890 sync.release();
894 assertHasWaitersUnlocked(sync, c, NO_THREADS);
901 final Mutex sync = new Mutex();
902 final ConditionObject c = sync.newCondition();
907 sync.acquire();
908 assertHasWaitersLocked(sync, c, NO_THREADS);
909 assertTrue(sync.getWaitingThreads(c).isEmpty());
912 sync.release();
917 sync.acquire();
918 assertHasWaitersLocked(sync, c, t1);
919 assertTrue(sync.getWaitingThreads(c).contains(t1));
920 assertFalse(sync.getWaitingThreads(c).isEmpty());
921 assertEquals(1, sync.getWaitingThreads(c).size());
924 sync.release();
927 sync.acquire();
928 assertHasWaitersLocked(sync, c, NO_THREADS);
929 assertFalse(sync.getWaitingThreads(c).contains(t1));
930 assertFalse(sync.getWaitingThreads(c).contains(t2));
931 assertTrue(sync.getWaitingThreads(c).isEmpty());
932 assertEquals(0, sync.getWaitingThreads(c).size());
933 sync.release();
937 sync.acquire();
938 assertHasWaitersLocked(sync, c, t1);
939 assertTrue(sync.getWaitingThreads(c).contains(t1));
940 assertFalse(sync.getWaitingThreads(c).contains(t2));
941 assertFalse(sync.getWaitingThreads(c).isEmpty());
942 assertEquals(1, sync.getWaitingThreads(c).size());
943 sync.release();
947 sync.acquire();
948 assertHasWaitersLocked(sync, c, t1, t2);
949 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
950 assertTrue(sync.getWaitingThreads(c).contains(t1));
951 assertTrue(sync.getWaitingThreads(c).contains(t2));
952 assertFalse(sync.getWaitingThreads(c).isEmpty());
953 assertEquals(2, sync.getWaitingThreads(c).size());
955 assertHasWaitersLocked(sync, c, NO_THREADS);
956 assertHasExclusiveQueuedThreads(sync, t1, t2);
957 assertFalse(sync.getWaitingThreads(c).contains(t1));
958 assertFalse(sync.getWaitingThreads(c).contains(t2));
959 assertTrue(sync.getWaitingThreads(c).isEmpty());
960 assertEquals(0, sync.getWaitingThreads(c).size());
961 sync.release();
965 assertHasWaitersUnlocked(sync, c, NO_THREADS);
972 final Mutex sync = new Mutex();
973 final ConditionObject c = sync.newCondition();
977 sync.acquire();
981 assertHasWaitersLocked(sync, c, NO_THREADS);
982 sync.release();
986 sync.acquire();
987 assertHasWaitersLocked(sync, c, t);
988 sync.release();
990 assertHasWaitersUnlocked(sync, c, t);
992 sync.acquire();
993 assertHasWaitersLocked(sync, c, t);
994 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
996 assertHasWaitersLocked(sync, c, NO_THREADS);
997 assertHasExclusiveQueuedThreads(sync, t);
998 sync.release();
1010 final Mutex sync = new Mutex();
1011 final ConditionObject c = sync.newCondition();
1015 sync.acquire();
1033 final Mutex sync = new Mutex();
1034 final ConditionObject c = sync.newCondition();
1039 sync.acquire();
1042 sync.release();
1047 sync.acquire();
1050 sync.release();
1055 sync.acquire();
1056 assertHasWaitersLocked(sync, c, t1, t2);
1057 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
1059 assertHasWaitersLocked(sync, c, NO_THREADS);
1060 assertHasExclusiveQueuedThreads(sync, t1, t2);
1061 sync.release();
1070 Mutex sync = new Mutex();
1071 assertTrue(sync.toString().contains("State = " + Mutex.UNLOCKED));
1072 sync.acquire();
1073 assertTrue(sync.toString().contains("State = " + Mutex.LOCKED));
1080 Mutex sync = new Mutex();
1081 assertFalse(serialClone(sync).isHeldExclusively());
1082 sync.acquire();
1083 Thread t = newStartedThread(new InterruptedSyncRunnable(sync));
1084 waitForQueuedThread(sync, t);
1085 assertTrue(sync.isHeldExclusively());
1087 Mutex clone = serialClone(sync);
1089 assertHasExclusiveQueuedThreads(sync, t);
1093 sync.release();
1094 assertFalse(sync.isHeldExclusively());
1096 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
1238 final Mutex sync = new Mutex();
1239 final ConditionObject c = sync.newCondition();
1240 sync.acquire();
1243 sync.release();
1250 final Mutex sync = new Mutex();
1251 final ConditionObject c = sync.newCondition();
1252 sync.acquire();
1255 sync.release();