package s.coroutines;

import java.util.Objects;
import kotlin.Metadata;
import kotlin.collections.j;
import s.coroutines.internal.ArrayQueue;

/* JADX INFO: renamed from: s.a.q0, reason: from Kotlin metadata */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u00008\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0005\n\u0002\u0010\t\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\u0007\n\u0002\u0010\b\n\u0002\b\u0005\b \u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\u0010\u0010\u0012\u001a\u00020\u00132\b\b\u0002\u0010\u0014\u001a\u00020\u0004J\u0010\u0010\u0015\u001a\u00020\n2\u0006\u0010\u0014\u001a\u00020\u0004H\u0002J\u0012\u0010\u0016\u001a\u00020\u00132\n\u0010\u0017\u001a\u0006\u0012\u0002\b\u00030\u0010J\u0010\u0010\u0018\u001a\u00020\u00132\b\b\u0002\u0010\u0014\u001a\u00020\u0004J\u000e\u0010\u0019\u001a\u00020\u00012\u0006\u0010\u001a\u001a\u00020\u001bJ\b\u0010\u001c\u001a\u00020\nH\u0016J\u0006\u0010\u001d\u001a\u00020\u0004J\b\u0010\u001e\u001a\u00020\u0004H\u0016J\b\u0010\u001f\u001a\u00020\u0013H\u0016R\u0011\u0010\u0003\u001a\u00020\u00048F¢\u0006\u0006\u001a\u0004\b\u0003\u0010\u0005R\u0014\u0010\u0006\u001a\u00020\u00048TX\u0094\u0004¢\u0006\u0006\u001a\u0004\b\u0006\u0010\u0005R\u0011\u0010\u0007\u001a\u00020\u00048F¢\u0006\u0006\u001a\u0004\b\u0007\u0010\u0005R\u0011\u0010\b\u001a\u00020\u00048F¢\u0006\u0006\u001a\u0004\b\b\u0010\u0005R\u0014\u0010\t\u001a\u00020\n8TX\u0094\u0004¢\u0006\u0006\u001a\u0004\b\u000b\u0010\fR\u000e\u0010\r\u001a\u00020\u0004X\u0082\u000e¢\u0006\u0002\n\u0000R\u001a\u0010\u000e\u001a\u000e\u0012\b\u0012\u0006\u0012\u0002\b\u00030\u0010\u0018\u00010\u000fX\u0082\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0011\u001a\u00020\nX\u0082\u000e¢\u0006\u0002\n\u0000¨\u0006 "}, d2 = {"Lkotlinx/coroutines/EventLoop;", "Lkotlinx/coroutines/CoroutineDispatcher;", "()V", "isActive", "", "()Z", "isEmpty", "isUnconfinedLoopActive", "isUnconfinedQueueEmpty", "nextTime", "", "getNextTime", "()J", "shared", "unconfinedQueue", "Lkotlinx/coroutines/internal/ArrayQueue;", "Lkotlinx/coroutines/DispatchedTask;", "useCount", "decrementUseCount", "", "unconfined", "delta", "dispatchUnconfined", "task", "incrementUseCount", "limitedParallelism", "parallelism", "", "processNextEvent", "processUnconfinedEvent", "shouldBeProcessedFromContext", "shutdown", "kotlinx-coroutines-core"}, k = 1, mv = {1, 6, 0}, xi = 48)
public abstract class EventLoop extends CoroutineDispatcher {

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public static final /* synthetic */ int f9467m = 0;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public long f9468n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public boolean f9469o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public ArrayQueue<DispatchedTask<?>> f9470p;

    public final void B(boolean z2) {
        long jC = this.f9468n - C(z2);
        this.f9468n = jC;
        if (jC <= 0 && this.f9469o) {
            shutdown();
        }
    }

    public final long C(boolean z2) {
        return z2 ? 4294967296L : 1L;
    }

    public final void D(DispatchedTask<?> dispatchedTask) {
        ArrayQueue<DispatchedTask<?>> arrayQueue = this.f9470p;
        if (arrayQueue == null) {
            arrayQueue = new ArrayQueue<>();
            this.f9470p = arrayQueue;
        }
        Object[] objArr = arrayQueue.a;
        int i2 = arrayQueue.f9330c;
        objArr[i2] = dispatchedTask;
        int length = (objArr.length - 1) & (i2 + 1);
        arrayQueue.f9330c = length;
        int i3 = arrayQueue.f9329b;
        if (length == i3) {
            int length2 = objArr.length;
            Object[] objArr2 = new Object[length2 << 1];
            j.j(objArr, objArr2, 0, i3, 0, 10);
            Object[] objArr3 = arrayQueue.a;
            int length3 = objArr3.length;
            int i4 = arrayQueue.f9329b;
            j.j(objArr3, objArr2, length3 - i4, 0, i4, 4);
            arrayQueue.a = objArr2;
            arrayQueue.f9329b = 0;
            arrayQueue.f9330c = length2;
        }
    }

    public final void E(boolean z2) {
        this.f9468n = C(z2) + this.f9468n;
        if (z2) {
            return;
        }
        this.f9469o = true;
    }

    public final boolean F() {
        return this.f9468n >= C(true);
    }

    public long G() {
        return !H() ? Long.MAX_VALUE : 0L;
    }

    public final boolean H() {
        ArrayQueue<DispatchedTask<?>> arrayQueue = this.f9470p;
        if (arrayQueue == null) {
            return false;
        }
        int i2 = arrayQueue.f9329b;
        Object obj = null;
        if (i2 != arrayQueue.f9330c) {
            Object[] objArr = arrayQueue.a;
            Object obj2 = objArr[i2];
            objArr[i2] = null;
            arrayQueue.f9329b = (i2 + 1) & (objArr.length - 1);
            Objects.requireNonNull(obj2, "null cannot be cast to non-null type T of kotlinx.coroutines.internal.ArrayQueue");
            obj = obj2;
        }
        DispatchedTask dispatchedTask = (DispatchedTask) obj;
        if (dispatchedTask == null) {
            return false;
        }
        dispatchedTask.run();
        return true;
    }

    public void shutdown() {
    }
}
