Rabbit-R1/original r1/java/sources/androidx/media3/common/util/ConditionVariable.java
2024-05-21 17:08:36 -04:00

72 lines
1.7 KiB
Java

package androidx.media3.common.util;
/* loaded from: classes2.dex */
public class ConditionVariable {
private final Clock clock;
private boolean isOpen;
public ConditionVariable() {
this(Clock.DEFAULT);
}
public ConditionVariable(Clock clock) {
this.clock = clock;
}
public synchronized boolean open() {
if (this.isOpen) {
return false;
}
this.isOpen = true;
notifyAll();
return true;
}
public synchronized boolean close() {
boolean z;
z = this.isOpen;
this.isOpen = false;
return z;
}
public synchronized void block() throws InterruptedException {
while (!this.isOpen) {
wait();
}
}
public synchronized boolean block(long j) throws InterruptedException {
if (j <= 0) {
return this.isOpen;
}
long elapsedRealtime = this.clock.elapsedRealtime();
long j2 = j + elapsedRealtime;
if (j2 < elapsedRealtime) {
block();
} else {
while (!this.isOpen && elapsedRealtime < j2) {
wait(j2 - elapsedRealtime);
elapsedRealtime = this.clock.elapsedRealtime();
}
}
return this.isOpen;
}
public synchronized void blockUninterruptible() {
boolean z = false;
while (!this.isOpen) {
try {
wait();
} catch (InterruptedException unused) {
z = true;
}
}
if (z) {
Thread.currentThread().interrupt();
}
}
public synchronized boolean isOpen() {
return this.isOpen;
}
}