2021-07-24 02:37:17 +00:00
|
|
|
package androidx.lifecycle;
|
|
|
|
|
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import androidx.annotation.AnyThread;
|
|
|
|
import androidx.annotation.MainThread;
|
2021-10-18 07:12:10 +00:00
|
|
|
import c0.z.d.m;
|
2021-07-24 02:37:17 +00:00
|
|
|
import java.util.ArrayDeque;
|
|
|
|
import java.util.Queue;
|
|
|
|
import kotlin.coroutines.CoroutineContext;
|
|
|
|
import kotlinx.coroutines.CoroutineDispatcher;
|
2021-10-18 07:12:10 +00:00
|
|
|
import r.a.a.n;
|
|
|
|
import r.a.j0;
|
|
|
|
import r.a.k1;
|
2021-07-24 02:37:17 +00:00
|
|
|
/* compiled from: DispatchQueue.kt */
|
|
|
|
public final class DispatchQueue {
|
|
|
|
private boolean finished;
|
|
|
|
private boolean isDraining;
|
|
|
|
private boolean paused = true;
|
|
|
|
private final Queue<Runnable> queue = new ArrayDeque();
|
|
|
|
|
|
|
|
public static final /* synthetic */ void access$enqueue(DispatchQueue dispatchQueue, Runnable runnable) {
|
|
|
|
dispatchQueue.enqueue(runnable);
|
|
|
|
}
|
|
|
|
|
|
|
|
@MainThread
|
|
|
|
private final void enqueue(Runnable runnable) {
|
|
|
|
if (this.queue.offer(runnable)) {
|
|
|
|
drainQueue();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
throw new IllegalStateException("cannot enqueue any more runnables".toString());
|
|
|
|
}
|
|
|
|
|
|
|
|
@MainThread
|
|
|
|
public final boolean canRun() {
|
|
|
|
return this.finished || !this.paused;
|
|
|
|
}
|
|
|
|
|
|
|
|
@AnyThread
|
|
|
|
@SuppressLint({"WrongThread"})
|
|
|
|
public final void dispatchAndEnqueue(CoroutineContext coroutineContext, Runnable runnable) {
|
|
|
|
m.checkNotNullParameter(coroutineContext, "context");
|
|
|
|
m.checkNotNullParameter(runnable, "runnable");
|
|
|
|
CoroutineDispatcher coroutineDispatcher = j0.a;
|
|
|
|
k1 H = n.b.H();
|
|
|
|
if (H.isDispatchNeeded(coroutineContext) || canRun()) {
|
|
|
|
H.dispatch(coroutineContext, new DispatchQueue$dispatchAndEnqueue$$inlined$with$lambda$1(this, coroutineContext, runnable));
|
|
|
|
} else {
|
|
|
|
enqueue(runnable);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@MainThread
|
|
|
|
public final void drainQueue() {
|
|
|
|
if (!this.isDraining) {
|
|
|
|
boolean z2 = false;
|
|
|
|
z2 = true;
|
|
|
|
try {
|
|
|
|
while (true) {
|
|
|
|
if (!(!this.queue.isEmpty())) {
|
|
|
|
break;
|
|
|
|
} else if (!canRun()) {
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
Runnable poll = this.queue.poll();
|
|
|
|
if (poll != null) {
|
|
|
|
poll.run();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
this.isDraining = false;
|
|
|
|
} finally {
|
|
|
|
this.isDraining = z2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@MainThread
|
|
|
|
public final void finish() {
|
|
|
|
this.finished = true;
|
|
|
|
drainQueue();
|
|
|
|
}
|
|
|
|
|
|
|
|
@MainThread
|
|
|
|
public final void pause() {
|
|
|
|
this.paused = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@MainThread
|
|
|
|
public final void resume() {
|
|
|
|
if (this.paused) {
|
|
|
|
if (!this.finished) {
|
|
|
|
this.paused = false;
|
|
|
|
drainQueue();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
throw new IllegalStateException("Cannot resume a finished dispatcher".toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|