mirror of
https://github.com/androidx/media.git
synced 2025-05-04 22:20:47 +08:00
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:
parent
c4385c738f
commit
a9ed6b191d
@ -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;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user