Switch from currentTimeMillis to elapsedRealtime

currentTimeMillis is not guaranteed to be monotonic and elapsedRealtime is
recommend for interval timing.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=176853118
This commit is contained in:
andrewlewis 2017-11-24 10:00:44 -08:00 committed by Oliver Woodman
parent c4385c738f
commit a9ed6b191d

View File

@ -60,18 +60,18 @@ public final class ConditionVariable {
}
/**
* Blocks until the condition is opened or until timeout milliseconds have passed.
* Blocks until the condition is opened or until {@code timeout} milliseconds have passed.
*
* @param timeout The maximum time to wait in milliseconds.
* @return true If the condition was opened, false if the call returns because of the timeout.
* @return True if the condition was opened, false if the call returns because of the timeout.
* @throws InterruptedException If the thread is interrupted.
*/
public synchronized boolean block(long timeout) throws InterruptedException {
long now = System.currentTimeMillis();
long now = android.os.SystemClock.elapsedRealtime();
long end = now + timeout;
while (!isOpen && now < end) {
wait(end - now);
now = System.currentTimeMillis();
now = android.os.SystemClock.elapsedRealtime();
}
return isOpen;
}