mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2025-01-01 12:02:30 -06:00
60 lines
1.8 KiB
Java
60 lines
1.8 KiB
Java
|
package androidx.media3.common;
|
||
|
|
||
|
import androidx.media3.common.util.Util;
|
||
|
import java.io.IOException;
|
||
|
import java.util.Collections;
|
||
|
import java.util.PriorityQueue;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
public final class PriorityTaskManager {
|
||
|
private final Object lock = new Object();
|
||
|
private final PriorityQueue<Integer> queue = new PriorityQueue<>(10, Collections.reverseOrder());
|
||
|
private int highestPriority = Integer.MIN_VALUE;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
public static class PriorityTooLowException extends IOException {
|
||
|
public PriorityTooLowException(int i, int i2) {
|
||
|
super("Priority too low [priority=" + i + ", highest=" + i2 + "]");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void add(int i) {
|
||
|
synchronized (this.lock) {
|
||
|
this.queue.add(Integer.valueOf(i));
|
||
|
this.highestPriority = Math.max(this.highestPriority, i);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void proceed(int i) throws InterruptedException {
|
||
|
synchronized (this.lock) {
|
||
|
while (this.highestPriority != i) {
|
||
|
this.lock.wait();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public boolean proceedNonBlocking(int i) {
|
||
|
boolean z;
|
||
|
synchronized (this.lock) {
|
||
|
z = this.highestPriority == i;
|
||
|
}
|
||
|
return z;
|
||
|
}
|
||
|
|
||
|
public void proceedOrThrow(int i) throws PriorityTooLowException {
|
||
|
synchronized (this.lock) {
|
||
|
if (this.highestPriority != i) {
|
||
|
throw new PriorityTooLowException(i, this.highestPriority);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public void remove(int i) {
|
||
|
synchronized (this.lock) {
|
||
|
this.queue.remove(Integer.valueOf(i));
|
||
|
this.highestPriority = this.queue.isEmpty() ? Integer.MIN_VALUE : ((Integer) Util.castNonNull(this.queue.peek())).intValue();
|
||
|
this.lock.notifyAll();
|
||
|
}
|
||
|
}
|
||
|
}
|