690 |
|
} |
691 |
|
|
692 |
|
/** |
693 |
< |
* Waits up to the specified number of milliseconds for the given |
693 |
> |
* Spin-waits up to the specified number of milliseconds for the given |
694 |
|
* thread to enter a wait state: BLOCKED, WAITING, or TIMED_WAITING. |
695 |
|
*/ |
696 |
|
void waitForThreadToEnterWaitState(Thread thread, long timeoutMillis) { |
697 |
< |
long timeoutNanos = timeoutMillis * 1000L * 1000L; |
698 |
< |
long t0 = System.nanoTime(); |
697 |
> |
long startTime = System.nanoTime(); |
698 |
|
for (;;) { |
699 |
|
Thread.State s = thread.getState(); |
700 |
|
if (s == Thread.State.BLOCKED || |
703 |
|
return; |
704 |
|
else if (s == Thread.State.TERMINATED) |
705 |
|
fail("Unexpected thread termination"); |
706 |
< |
else if (System.nanoTime() - t0 > timeoutNanos) { |
706 |
> |
else if (millisElapsedSince(startTime) > timeoutMillis) { |
707 |
|
threadAssertTrue(thread.isAlive()); |
708 |
|
return; |
709 |
|
} |
902 |
|
} catch (Throwable t) { |
903 |
|
threadUnexpectedException(t); |
904 |
|
} |
905 |
+ |
} |
906 |
+ |
|
907 |
+ |
public void await(Semaphore semaphore) { |
908 |
+ |
try { |
909 |
+ |
assertTrue(semaphore.tryAcquire(LONG_DELAY_MS, MILLISECONDS)); |
910 |
+ |
} catch (Throwable t) { |
911 |
+ |
threadUnexpectedException(t); |
912 |
+ |
} |
913 |
|
} |
914 |
|
|
915 |
|
// /** |