/** * Spin-waits until sync.isQueued(t) becomes true. */ void waitForQueuedThread(AbstractQueuedLongSynchronizer sync, Thread t) { long startTime = System.nanoTime(); while (!sync.isQueued(t)) { if (millisElapsedSince(startTime) > LONG_DELAY_MS) throw new AssertionFailedError("timed out"); Thread.yield(); } assertTrue(t.isAlive()); }
/** * Checks that sync has exactly the given queued threads. */ void assertHasQueuedThreads(AbstractQueuedLongSynchronizer sync, Thread... expected) { Collection<Thread> actual = sync.getQueuedThreads(); assertEquals(expected.length > 0, sync.hasQueuedThreads()); assertEquals(expected.length, sync.getQueueLength()); assertEquals(expected.length, actual.size()); assertEquals(expected.length == 0, actual.isEmpty()); assertEquals(new HashSet<Thread>(actual), new HashSet<Thread>(Arrays.asList(expected))); }
/** * Checks that sync has exactly the given (exclusive) queued threads. */ void assertHasExclusiveQueuedThreads(AbstractQueuedLongSynchronizer sync, Thread... expected) { assertHasQueuedThreads(sync, expected); assertEquals(new HashSet<Thread>(sync.getExclusiveQueuedThreads()), new HashSet<Thread>(sync.getQueuedThreads())); assertEquals(0, sync.getSharedQueuedThreads().size()); assertTrue(sync.getSharedQueuedThreads().isEmpty()); }
/** * Checks that sync has exactly the given (shared) queued threads. */ void assertHasSharedQueuedThreads(AbstractQueuedLongSynchronizer sync, Thread... expected) { assertHasQueuedThreads(sync, expected); assertEquals(new HashSet<Thread>(sync.getSharedQueuedThreads()), new HashSet<Thread>(sync.getQueuedThreads())); assertEquals(0, sync.getExclusiveQueuedThreads().size()); assertTrue(sync.getExclusiveQueuedThreads().isEmpty()); }