Home | History | Annotate | Download | only in jsr166

Lines Matching refs:sync

116         final Mutex sync;
117 InterruptibleSyncRunnable(Mutex sync) { this.sync = sync; }
119 sync.acquireInterruptibly();
128 final Mutex sync;
129 InterruptedSyncRunnable(Mutex sync) { this.sync = sync; }
131 sync.acquireInterruptibly();
139 * Spin-waits until sync.isQueued(t) becomes true.
141 void waitForQueuedThread(AbstractQueuedSynchronizer sync, Thread t) {
143 while (!sync.isQueued(t)) {
152 * Checks that sync has exactly the given queued threads.
154 void assertHasQueuedThreads(AbstractQueuedSynchronizer sync,
156 Collection<Thread> actual = sync.getQueuedThreads();
157 assertEquals(expected.length > 0, sync.hasQueuedThreads());
158 assertEquals(expected.length, sync.getQueueLength());
166 * Checks that sync has exactly the given (exclusive) queued threads.
168 void assertHasExclusiveQueuedThreads(AbstractQueuedSynchronizer sync,
170 assertHasQueuedThreads(sync, expected);
171 assertEquals(new HashSet<Thread>(sync.getExclusiveQueuedThreads()),
172 new HashSet<Thread>(sync.getQueuedThreads()));
173 assertEquals(0, sync.getSharedQueuedThreads().size());
174 assertTrue(sync.getSharedQueuedThreads().isEmpty());
178 * Checks that sync has exactly the given (shared) queued threads.
180 void assertHasSharedQueuedThreads(AbstractQueuedSynchronizer sync,
182 assertHasQueuedThreads(sync, expected);
183 assertEquals(new HashSet<Thread>(sync.getSharedQueuedThreads()),
184 new HashSet<Thread>(sync.getQueuedThreads()));
185 assertEquals(0, sync.getExclusiveQueuedThreads().size());
186 assertTrue(sync.getExclusiveQueuedThreads().isEmpty());
193 void assertHasWaitersUnlocked(Mutex sync, ConditionObject c,
195 sync.acquire();
196 assertHasWaitersLocked(sync, c, threads);
197 sync.release();
203 void assertHasWaitersLocked(Mutex sync, ConditionObject c,
205 assertEquals(threads.length > 0, sync.hasWaiters(c));
206 assertEquals(threads.length, sync.getWaitQueueLength(c));
207 assertEquals(threads.length == 0, sync.getWaitingThreads(c).isEmpty());
208 assertEquals(threads.length, sync.getWaitingThreads(c).size());
209 assertEquals(new HashSet<Thread>(sync.getWaitingThreads(c)),
280 Mutex sync = new Mutex();
281 assertFalse(sync.isHeldExclusively());
285 * acquiring released sync succeeds
288 Mutex sync = new Mutex();
289 sync.acquire();
290 assertTrue(sync.isHeldExclusively());
291 sync.release();
292 assertFalse(sync.isHeldExclusively());
296 * tryAcquire on a released sync succeeds
299 Mutex sync = new Mutex();
300 assertTrue(sync.tryAcquire());
301 assertTrue(sync.isHeldExclusively());
302 sync.release();
303 assertFalse(sync.isHeldExclusively());
310 final Mutex sync = new Mutex();
311 assertFalse(sync.hasQueuedThreads());
312 sync.acquire();
313 Thread t1 = newStartedThread(new InterruptedSyncRunnable(sync));
314 waitForQueuedThread(sync, t1);
315 assertTrue(sync.hasQueuedThreads());
316 Thread t2 = newStartedThread(new InterruptibleSyncRunnable(sync));
317 waitForQueuedThread(sync, t2);
318 assertTrue(sync.hasQueuedThreads());
321 assertTrue(sync.hasQueuedThreads());
322 sync.release();
324 assertFalse(sync.hasQueuedThreads());
331 final Mutex sync = new Mutex();
333 sync.isQueued(null);
342 final Mutex sync = new Mutex();
343 Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
344 Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
345 assertFalse(sync.isQueued(t1));
346 assertFalse(sync.isQueued(t2));
347 sync.acquire();
349 waitForQueuedThread(sync, t1);
350 assertTrue(sync.isQueued(t1));
351 assertFalse(sync.isQueued(t2));
353 waitForQueuedThread(sync, t2);
354 assertTrue(sync.isQueued(t1));
355 assertTrue(sync.isQueued(t2));
358 assertFalse(sync.isQueued(t1));
359 assertTrue(sync.isQueued(t2));
360 sync.release();
362 assertFalse(sync.isQueued(t1));
363 assertFalse(sync.isQueued(t2));
370 final Mutex sync = new Mutex();
371 assertNull(sync.getFirstQueuedThread());
372 sync.acquire();
373 Thread t1 = newStartedThread(new InterruptedSyncRunnable(sync));
374 waitForQueuedThread(sync, t1);
375 assertEquals(t1, sync.getFirstQueuedThread());
376 Thread t2 = newStartedThread(new InterruptibleSyncRunnable(sync));
377 waitForQueuedThread(sync, t2);
378 assertEquals(t1, sync.getFirstQueuedThread());
381 assertEquals(t2, sync.getFirstQueuedThread());
382 sync.release();
384 assertNull(sync.getFirstQueuedThread());
391 final Mutex sync = new Mutex();
392 assertFalse(sync.hasContended());
393 sync.acquire();
394 assertFalse(sync.hasContended());
395 Thread t1 = newStartedThread(new InterruptedSyncRunnable(sync));
396 waitForQueuedThread(sync, t1);
397 assertTrue(sync.hasContended());
398 Thread t2 = newStartedThread(new InterruptibleSyncRunnable(sync));
399 waitForQueuedThread(sync, t2);
400 assertTrue(sync.hasContended());
403 assertTrue(sync.hasContended());
404 sync.release();
406 assertTrue(sync.hasContended());
413 final Mutex sync = new Mutex();
414 Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
415 Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
416 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
417 sync.acquire();
418 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
420 waitForQueuedThread(sync, t1);
421 assertHasExclusiveQueuedThreads(sync, t1);
422 assertTrue(sync.getQueuedThreads().contains(t1));
423 assertFalse(sync.getQueuedThreads().contains(t2));
425 waitForQueuedThread(sync, t2);
426 assertHasExclusiveQueuedThreads(sync, t1, t2);
427 assertTrue(sync.getQueuedThreads().contains(t1));
428 assertTrue(sync.getQueuedThreads().contains(t2));
431 assertHasExclusiveQueuedThreads(sync, t2);
432 sync.release();
434 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
441 final Mutex sync = new Mutex();
442 Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
443 Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
444 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
445 sync.acquire();
446 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
448 waitForQueuedThread(sync, t1);
449 assertHasExclusiveQueuedThreads(sync, t1);
450 assertTrue(sync.getExclusiveQueuedThreads().contains(t1));
451 assertFalse(sync.getExclusiveQueuedThreads().contains(t2));
453 waitForQueuedThread(sync, t2);
454 assertHasExclusiveQueuedThreads(sync, t1, t2);
455 assertTrue(sync.getExclusiveQueuedThreads().contains(t1));
456 assertTrue(sync.getExclusiveQueuedThreads().contains(t2));
459 sync, t2);
460 sync.release();
462 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
469 final Mutex sync = new Mutex();
470 assertTrue(sync.getSharedQueuedThreads().isEmpty());
471 sync.acquire();
472 assertTrue(sync.getSharedQueuedThreads().isEmpty());
473 Thread t1 = newStartedThread(new InterruptedSyncRunnable(sync));
474 waitForQueuedThread(sync, t1);
475 assertTrue(sync.getSharedQueuedThreads().isEmpty());
476 Thread t2 = newStartedThread(new InterruptibleSyncRunnable(sync));
477 waitForQueuedThread(sync, t2);
478 assertTrue(sync.getSharedQueuedThreads().isEmpty());
481 assertTrue(sync.getSharedQueuedThreads().isEmpty());
482 sync.release();
484 assertTrue(sync.getSharedQueuedThreads().isEmpty());
517 final Mutex sync = new Mutex();
518 sync.acquire();
521 sync.tryAcquireNanos(MILLISECONDS.toNanos(2 * LONG_DELAY_MS));
524 waitForQueuedThread(sync, t);
530 * tryAcquire on exclusively held sync fails
533 final Mutex sync = new Mutex();
534 sync.acquire();
537 assertFalse(sync.tryAcquire());
541 sync.release();
545 * tryAcquireNanos on an exclusively held sync times out
548 final Mutex sync = new Mutex();
549 sync.acquire();
554 assertFalse(sync.tryAcquireNanos(nanos));
559 sync.release();
566 final Mutex sync = new Mutex();
567 sync.acquire();
568 assertTrue(sync.isHeldExclusively());
569 sync.release();
570 assertFalse(sync.isHeldExclusively());
576 sync.acquire();
579 sync.release();
583 assertTrue(sync.isHeldExclusively());
586 assertFalse(sync.isHeldExclusively());
593 final Mutex sync = new Mutex();
595 sync.acquireInterruptibly();
599 sync.acquireInterruptibly();
603 waitForQueuedThread(sync, t);
606 assertTrue(sync.isHeldExclusively());
610 * owns is true for a condition created by sync else false
613 final Mutex sync = new Mutex();
614 final ConditionObject c = sync.newCondition();
616 assertTrue(sync.owns(c));
621 * Calling await without holding sync throws IllegalMonitorStateException
624 final Mutex sync = new Mutex();
625 final ConditionObject c = sync.newCondition();
638 * Calling signal without holding sync throws IllegalMonitorStateException
641 final Mutex sync = new Mutex();
642 final ConditionObject c = sync.newCondition();
647 assertHasWaitersUnlocked(sync, c, NO_THREADS);
651 * Calling signalAll without holding sync throws IllegalMonitorStateException
654 final Mutex sync = new Mutex();
655 final ConditionObject c = sync.newCondition();
669 final Mutex sync = new Mutex();
670 final ConditionObject c = sync.newCondition();
671 sync.acquire();
673 sync.release();
684 final Mutex sync = new Mutex();
685 final ConditionObject c = sync.newCondition();
689 sync.acquire();
692 sync.release();
696 sync.acquire();
697 assertHasWaitersLocked(sync, c, t);
698 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
700 assertHasWaitersLocked(sync, c, NO_THREADS);
701 assertHasExclusiveQueuedThreads(sync, t);
702 sync.release();
710 final Mutex sync = new Mutex();
712 sync.hasWaiters(null);
721 final Mutex sync = new Mutex();
723 sync.getWaitQueueLength(null);
732 final Mutex sync = new Mutex();
734 sync.getWaitingThreads(null);
743 final Mutex sync = new Mutex();
744 final ConditionObject c = sync.newCondition();
750 assertHasWaitersUnlocked(sync, c, NO_THREADS);
757 final Mutex sync = new Mutex();
758 final ConditionObject c = sync.newCondition();
760 sync.hasWaiters(c);
763 assertHasWaitersUnlocked(sync, c, NO_THREADS);
770 final Mutex sync = new Mutex();
771 final ConditionObject c = sync.newCondition();
777 assertHasWaitersUnlocked(sync, c, NO_THREADS);
784 final Mutex sync = new Mutex();
785 final ConditionObject c = sync.newCondition();
787 sync.getWaitQueueLength(c);
790 assertHasWaitersUnlocked(sync, c, NO_THREADS);
797 final Mutex sync = new Mutex();
798 final ConditionObject c = sync.newCondition();
804 assertHasWaitersUnlocked(sync, c, NO_THREADS);
811 final Mutex sync = new Mutex();
812 final ConditionObject c = sync.newCondition();
814 sync.getWaitingThreads(c);
817 assertHasWaitersUnlocked(sync, c, NO_THREADS);
824 final Mutex sync = new Mutex();
825 final ConditionObject c = sync.newCondition();
829 sync.acquire();
830 assertHasWaitersLocked(sync, c, NO_THREADS);
831 assertFalse(sync.hasWaiters(c));
834 sync.release();
838 sync.acquire();
839 assertHasWaitersLocked(sync, c, t);
840 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
841 assertTrue(sync.hasWaiters(c));
843 assertHasWaitersLocked(sync, c, NO_THREADS);
844 assertHasExclusiveQueuedThreads(sync, t);
845 assertFalse(sync.hasWaiters(c));
846 sync.release();
849 assertHasWaitersUnlocked(sync, c, NO_THREADS);
856 final Mutex sync = new Mutex();
857 final ConditionObject c = sync.newCondition();
862 sync.acquire();
863 assertHasWaitersLocked(sync, c, NO_THREADS);
864 assertEquals(0, sync.getWaitQueueLength(c));
867 sync.release();
870 sync.acquire();
871 assertHasWaitersLocked(sync, c, t1);
872 assertEquals(1, sync.getWaitQueueLength(c));
873 sync.release();
877 sync.acquire();
878 assertHasWaitersLocked(sync, c, t1);
879 assertEquals(1, sync.getWaitQueueLength(c));
882 sync.release();
885 sync.acquire();
886 assertHasWaitersLocked(sync, c, t1, t2);
887 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
888 assertEquals(2, sync.getWaitQueueLength(c));
890 assertHasWaitersLocked(sync, c, NO_THREADS);
891 assertHasExclusiveQueuedThreads(sync, t1, t2);
892 assertEquals(0, sync.getWaitQueueLength(c));
893 sync.release();
897 assertHasWaitersUnlocked(sync, c, NO_THREADS);
904 final Mutex sync = new Mutex();
905 final ConditionObject c = sync.newCondition();
910 sync.acquire();
911 assertHasWaitersLocked(sync, c, NO_THREADS);
912 assertTrue(sync.getWaitingThreads(c).isEmpty());
915 sync.release();
920 sync.acquire();
921 sync, c, t1);
922 assertTrue(sync.getWaitingThreads(c).contains(t1));
923 assertFalse(sync.getWaitingThreads(c).isEmpty());
924 assertEquals(1, sync.getWaitingThreads(c).size());
927 sync.release();
930 sync.acquire();
931 assertHasWaitersLocked(sync, c, NO_THREADS);
932 assertFalse(sync.getWaitingThreads(c).contains(t1));
933 assertFalse(sync.getWaitingThreads(c).contains(t2));
934 assertTrue(sync.getWaitingThreads(c).isEmpty());
935 assertEquals(0, sync.getWaitingThreads(c).size());
936 sync.release();
940 sync.acquire();
941 assertHasWaitersLocked(sync, c, t1);
942 assertTrue(sync.getWaitingThreads(c).contains(t1));
943 assertFalse(sync.getWaitingThreads(c).contains(t2));
944 assertFalse(sync.getWaitingThreads(c).isEmpty());
945 assertEquals(1, sync.getWaitingThreads(c).size());
946 sync.release();
950 sync.acquire();
951 assertHasWaitersLocked(sync, c, t1, t2);
952 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
953 assertTrue(sync.getWaitingThreads(c).contains(t1));
954 assertTrue(sync.getWaitingThreads(c).contains(t2));
955 assertFalse(sync.getWaitingThreads(c).isEmpty());
956 assertEquals(2, sync.getWaitingThreads(c).size());
958 assertHasWaitersLocked(sync, c, NO_THREADS);
959 assertHasExclusiveQueuedThreads(sync, t1, t2);
960 assertFalse(sync.getWaitingThreads(c).contains(t1));
961 assertFalse(sync.getWaitingThreads(c).contains(t2));
962 assertTrue(sync.getWaitingThreads(c).isEmpty());
963 assertEquals(0, sync.getWaitingThreads(c).size());
964 sync.release();
968 assertHasWaitersUnlocked(sync, c, NO_THREADS);
975 final Mutex sync = new Mutex();
976 final ConditionObject c = sync.newCondition();
980 sync.acquire();
984 assertHasWaitersLocked(sync, c, NO_THREADS);
985 sync.release();
989 sync.acquire();
990 assertHasWaitersLocked(sync, c, t);
991 sync.release();
993 assertHasWaitersUnlocked(sync, c, t);
995 sync.acquire();
996 assertHasWaitersLocked(sync, c, t);
997 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
999 assertHasWaitersLocked(sync, c, NO_THREADS);
1000 assertHasExclusiveQueuedThreads(sync, t);
1001 sync.release();
1013 final Mutex sync = new Mutex();
1014 final ConditionObject c = sync.newCondition();
1018 sync.acquire();
1036 final Mutex sync = new Mutex();
1037 final ConditionObject c = sync.newCondition();
1042 sync.acquire();
1045 sync.release();
1050 sync.acquire();
1053 sync.release();
1058 sync.acquire();
1059 assertHasWaitersLocked(sync, c, t1, t2);
1060 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
1062 assertHasWaitersLocked(sync, c, NO_THREADS);
1063 assertHasExclusiveQueuedThreads(sync, t1, t2);
1064 sync.release();
1073 Mutex sync = new Mutex();
1074 assertTrue(sync.toString().contains("State = " + Mutex.UNLOCKED));
1075 sync.acquire();
1076 assertTrue(sync.toString().contains("State = " + Mutex.LOCKED));
1083 Mutex sync = new Mutex();
1084 assertFalse(serialClone(sync).isHeldExclusively());
1085 sync.acquire();
1086 Thread t = newStartedThread(new InterruptedSyncRunnable(sync));
1087 waitForQueuedThread(sync, t);
1088 assertTrue(sync.isHeldExclusively());
1090 Mutex clone = serialClone(sync);
1092 assertHasExclusiveQueuedThreads(sync, t);
1096 sync.release();
1097 assertFalse(sync.isHeldExclusively());
1099 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
1241 final Mutex sync = new Mutex();
1242 final ConditionObject c = sync.newCondition();
1243 sync.acquire();
1246 sync.release();
1253 final Mutex sync = new Mutex();
1254 final ConditionObject c = sync.newCondition();
1255 sync.acquire();
1258 sync.release();