Home | History | Annotate | Download | only in jsr166

Lines Matching refs:sync

112         final Mutex sync;
113 InterruptibleSyncRunnable(Mutex sync) { this.sync = sync; }
115 sync.acquireInterruptibly();
124 final Mutex sync;
125 InterruptedSyncRunnable(Mutex sync) { this.sync = sync; }
127 sync.acquireInterruptibly();
135 * Spin-waits until sync.isQueued(t) becomes true.
137 void waitForQueuedThread(AbstractQueuedLongSynchronizer sync,
140 while (!sync.isQueued(t)) {
149 * Checks that sync has exactly the given queued threads.
151 void assertHasQueuedThreads(AbstractQueuedLongSynchronizer sync,
153 Collection<Thread> actual = sync.getQueuedThreads();
154 assertEquals(expected.length > 0, sync.hasQueuedThreads());
155 assertEquals(expected.length, sync.getQueueLength());
163 * Checks that sync has exactly the given (exclusive) queued threads.
165 void assertHasExclusiveQueuedThreads(AbstractQueuedLongSynchronizer sync,
167 assertHasQueuedThreads(sync, expected);
168 assertEquals(new HashSet<Thread>(sync.getExclusiveQueuedThreads()),
169 new HashSet<Thread>(sync.getQueuedThreads()));
170 assertEquals(0, sync.getSharedQueuedThreads().size());
171 assertTrue(sync.getSharedQueuedThreads().isEmpty());
175 * Checks that sync has exactly the given (shared) queued threads.
177 void assertHasSharedQueuedThreads(AbstractQueuedLongSynchronizer sync,
179 assertHasQueuedThreads(sync, expected);
180 assertEquals(new HashSet<Thread>(sync.getSharedQueuedThreads()),
181 new HashSet<Thread>(sync.getQueuedThreads()));
182 assertEquals(0, sync.getExclusiveQueuedThreads().size());
183 assertTrue(sync.getExclusiveQueuedThreads().isEmpty());
190 void assertHasWaitersUnlocked(Mutex sync, ConditionObject c,
192 sync.acquire();
193 assertHasWaitersLocked(sync, c, threads);
194 sync.release();
200 void assertHasWaitersLocked(Mutex sync, ConditionObject c,
202 assertEquals(threads.length > 0, sync.hasWaiters(c));
203 assertEquals(threads.length, sync.getWaitQueueLength(c));
204 assertEquals(threads.length == 0, sync.getWaitingThreads(c).isEmpty());
205 assertEquals(threads.length, sync.getWaitingThreads(c).size());
206 assertEquals(new HashSet<Thread>(sync.getWaitingThreads(c)),
277 Mutex sync = new Mutex();
278 assertFalse(sync.isHeldExclusively());
282 * acquiring released sync succeeds
285 Mutex sync = new Mutex();
286 sync.acquire();
287 assertTrue(sync.isHeldExclusively());
288 sync.release();
289 assertFalse(sync.isHeldExclusively());
293 * tryAcquire on a released sync succeeds
296 Mutex sync = new Mutex();
297 assertTrue(sync.tryAcquire());
298 assertTrue(sync.isHeldExclusively());
299 sync.release();
300 assertFalse(sync.isHeldExclusively());
307 final Mutex sync = new Mutex();
308 assertFalse(sync.hasQueuedThreads());
309 sync.acquire();
310 Thread t1 = newStartedThread(new InterruptedSyncRunnable(sync));
311 waitForQueuedThread(sync, t1);
312 assertTrue(sync.hasQueuedThreads());
313 Thread t2 = newStartedThread(new InterruptibleSyncRunnable(sync));
314 waitForQueuedThread(sync, t2);
315 assertTrue(sync.hasQueuedThreads());
318 assertTrue(sync.hasQueuedThreads());
319 sync.release();
321 assertFalse(sync.hasQueuedThreads());
328 final Mutex sync = new Mutex();
330 sync.isQueued(null);
339 final Mutex sync = new Mutex();
340 Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
341 Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
342 assertFalse(sync.isQueued(t1));
343 assertFalse(sync.isQueued(t2));
344 sync.acquire();
346 waitForQueuedThread(sync, t1);
347 assertTrue(sync.isQueued(t1));
348 assertFalse(sync.isQueued(t2));
350 waitForQueuedThread(sync, t2);
351 assertTrue(sync.isQueued(t1));
352 assertTrue(sync.isQueued(t2));
355 assertFalse(sync.isQueued(t1));
356 assertTrue(sync.isQueued(t2));
357 sync.release();
359 assertFalse(sync.isQueued(t1));
360 assertFalse(sync.isQueued(t2));
367 final Mutex sync = new Mutex();
368 assertNull(sync.getFirstQueuedThread());
369 sync.acquire();
370 Thread t1 = newStartedThread(new InterruptedSyncRunnable(sync));
371 waitForQueuedThread(sync, t1);
372 assertEquals(t1, sync.getFirstQueuedThread());
373 Thread t2 = newStartedThread(new InterruptibleSyncRunnable(sync));
374 waitForQueuedThread(sync, t2);
375 assertEquals(t1, sync.getFirstQueuedThread());
378 assertEquals(t2, sync.getFirstQueuedThread());
379 sync.release();
381 assertNull(sync.getFirstQueuedThread());
388 final Mutex sync = new Mutex();
389 assertFalse(sync.hasContended());
390 sync.acquire();
391 assertFalse(sync.hasContended());
392 Thread t1 = newStartedThread(new InterruptedSyncRunnable(sync));
393 waitForQueuedThread(sync, t1);
394 assertTrue(sync.hasContended());
395 Thread t2 = newStartedThread(new InterruptibleSyncRunnable(sync));
396 waitForQueuedThread(sync, t2);
397 assertTrue(sync.hasContended());
400 assertTrue(sync.hasContended());
401 sync.release();
403 assertTrue(sync.hasContended());
410 final Mutex sync = new Mutex();
411 Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
412 Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
413 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
414 sync.acquire();
415 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
417 waitForQueuedThread(sync, t1);
418 assertHasExclusiveQueuedThreads(sync, t1);
419 assertTrue(sync.getQueuedThreads().contains(t1));
420 assertFalse(sync.getQueuedThreads().contains(t2));
422 waitForQueuedThread(sync, t2);
423 assertHasExclusiveQueuedThreads(sync, t1, t2);
424 assertTrue(sync.getQueuedThreads().contains(t1));
425 assertTrue(sync.getQueuedThreads().contains(t2));
428 assertHasExclusiveQueuedThreads(sync, t2);
429 sync.release();
431 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
438 final Mutex sync = new Mutex();
439 Thread t1 = new Thread(new InterruptedSyncRunnable(sync));
440 Thread t2 = new Thread(new InterruptibleSyncRunnable(sync));
441 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
442 sync.acquire();
443 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
445 waitForQueuedThread(sync, t1);
446 assertHasExclusiveQueuedThreads(sync, t1);
447 assertTrue(sync.getExclusiveQueuedThreads().contains(t1));
448 assertFalse(sync.getExclusiveQueuedThreads().contains(t2));
450 waitForQueuedThread(sync, t2);
451 assertHasExclusiveQueuedThreads(sync, t1, t2);
452 assertTrue(sync.getExclusiveQueuedThreads().contains(t1));
453 assertTrue(sync.getExclusiveQueuedThreads().contains(t2));
456 assertHasExclusiveQueuedThreads(sync, t2);
457 sync.release();
459 assertHasExclusiveQueuedThreads(sync, NO_THREADS);
466 final Mutex sync = new Mutex();
467 assertTrue(sync.getSharedQueuedThreads().isEmpty());
468 sync.acquire();
469 assertTrue(sync.getSharedQueuedThreads().isEmpty());
470 Thread t1 = newStartedThread(new InterruptedSyncRunnable(sync));
471 waitForQueuedThread(sync, t1);
472 assertTrue(sync.getSharedQueuedThreads().isEmpty());
473 Thread t2 = newStartedThread(new InterruptibleSyncRunnable(sync));
474 waitForQueuedThread(sync, t2);
475 assertTrue(sync.getSharedQueuedThreads().isEmpty());
478 assertTrue(sync.getSharedQueuedThreads().isEmpty());
479 sync.release();
481 assertTrue(sync.getSharedQueuedThreads().isEmpty());
514 final Mutex sync = new Mutex();
515 sync.acquire();
518 sync.tryAcquireNanos(MILLISECONDS.toNanos(2 * LONG_DELAY_MS));
521 waitForQueuedThread(sync, t);
527 * tryAcquire on exclusively held sync fails
530 final Mutex sync = new Mutex();
531 sync.acquire();
534 assertFalse(sync.tryAcquire());
538 sync.release();
542 * tryAcquireNanos on an exclusively held sync times out
545 final Mutex sync = new Mutex();
546 sync.acquire();
551 assertFalse(sync.tryAcquireNanos(nanos));
556 sync.release();
563 final Mutex sync = new Mutex();
564 sync.acquire();
565 assertTrue(sync.isHeldExclusively());
566 sync.release();
567 assertFalse(sync.isHeldExclusively());
573 sync.acquire();
576 sync.release();
580 assertTrue(sync.isHeldExclusively());
583 assertFalse(sync.isHeldExclusively());
590 final Mutex sync = new Mutex();
592 sync.acquireInterruptibly();
596 sync.acquireInterruptibly();
600 waitForQueuedThread(sync, t);
603 assertTrue(sync.isHeldExclusively());
607 * owns is true for a condition created by sync else false
610 final Mutex sync = new Mutex();
611 final ConditionObject c = sync.newCondition();
613 assertTrue(sync.owns(c));
618 * Calling await without holding sync throws IllegalMonitorStateException
621 final Mutex sync = new Mutex();
622 final ConditionObject c = sync.newCondition();
635 * Calling signal without holding sync throws IllegalMonitorStateException
638 final Mutex sync = new Mutex();
639 final ConditionObject c = sync.newCondition();
644 assertHasWaitersUnlocked(sync, c, NO_THREADS);
648 * Calling signalAll without holding sync throws IllegalMonitorStateException
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 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();