package s.coroutines;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import java.util.concurrent.locks.LockSupport;
import kotlin.Metadata;
import kotlin.Unit;
import kotlin.coroutines.CoroutineContext;
import kotlin.jvm.internal.o;
import kotlinx.serialization.json.internal.AbstractJsonLexerKt;
import s.coroutines.internal.ArrayQueue;
import s.coroutines.internal.LockFreeTaskQueueCore;
import s.coroutines.internal.Symbol;
import s.coroutines.internal.ThreadSafeHeap;
import s.coroutines.internal.ThreadSafeHeapNode;

/* JADX INFO: renamed from: s.a.r0, reason: from Kotlin metadata */
/* JADX INFO: loaded from: classes2.dex */
@Metadata(d1 = {"\u0000Z\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0007\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0010\t\n\u0002\b\u0005\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\b\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0013\n\u0002\u0018\u0002\n\u0002\u0018\u0002\b \u0018\u00002\u0002092\u00020::\u00044567B\u0007¢\u0006\u0004\b\u0001\u0010\u0002J\u000f\u0010\u0004\u001a\u00020\u0003H\u0002¢\u0006\u0004\b\u0004\u0010\u0002J\u0017\u0010\u0007\u001a\n\u0018\u00010\u0005j\u0004\u0018\u0001`\u0006H\u0002¢\u0006\u0004\b\u0007\u0010\bJ!\u0010\f\u001a\u00020\u00032\u0006\u0010\n\u001a\u00020\t2\n\u0010\u000b\u001a\u00060\u0005j\u0002`\u0006¢\u0006\u0004\b\f\u0010\rJ\u001b\u0010\u000f\u001a\u00020\u00032\n\u0010\u000e\u001a\u00060\u0005j\u0002`\u0006H\u0016¢\u0006\u0004\b\u000f\u0010\u0010J\u001b\u0010\u0012\u001a\u00020\u00112\n\u0010\u000e\u001a\u00060\u0005j\u0002`\u0006H\u0002¢\u0006\u0004\b\u0012\u0010\u0013J\u000f\u0010\u0015\u001a\u00020\u0014H\u0016¢\u0006\u0004\b\u0015\u0010\u0016J\u000f\u0010\u0017\u001a\u00020\u0003H\u0002¢\u0006\u0004\b\u0017\u0010\u0002J\u000f\u0010\u0018\u001a\u00020\u0003H\u0004¢\u0006\u0004\b\u0018\u0010\u0002J\u001d\u0010\u001c\u001a\u00020\u00032\u0006\u0010\u0019\u001a\u00020\u00142\u0006\u0010\u001b\u001a\u00020\u001a¢\u0006\u0004\b\u001c\u0010\u001dJ\u001f\u0010\u001f\u001a\u00020\u001e2\u0006\u0010\u0019\u001a\u00020\u00142\u0006\u0010\u001b\u001a\u00020\u001aH\u0002¢\u0006\u0004\b\u001f\u0010 J#\u0010#\u001a\u00020\"2\u0006\u0010!\u001a\u00020\u00142\n\u0010\u000b\u001a\u00060\u0005j\u0002`\u0006H\u0004¢\u0006\u0004\b#\u0010$J%\u0010'\u001a\u00020\u00032\u0006\u0010!\u001a\u00020\u00142\f\u0010&\u001a\b\u0012\u0004\u0012\u00020\u00030%H\u0016¢\u0006\u0004\b'\u0010(J\u0017\u0010)\u001a\u00020\u00112\u0006\u0010\u000e\u001a\u00020\u001aH\u0002¢\u0006\u0004\b)\u0010*J\u000f\u0010+\u001a\u00020\u0003H\u0016¢\u0006\u0004\b+\u0010\u0002R$\u0010-\u001a\u00020\u00112\u0006\u0010,\u001a\u00020\u00118B@BX\u0082\u000e¢\u0006\f\u001a\u0004\b-\u0010.\"\u0004\b/\u00100R\u0014\u00101\u001a\u00020\u00118TX\u0094\u0004¢\u0006\u0006\u001a\u0004\b1\u0010.R\u0014\u00103\u001a\u00020\u00148TX\u0094\u0004¢\u0006\u0006\u001a\u0004\b2\u0010\u0016¨\u00068"}, d2 = {"Lkotlinx/coroutines/EventLoopImplBase;", "<init>", "()V", "", "closeQueue", "Ljava/lang/Runnable;", "Lkotlinx/coroutines/Runnable;", "dequeue", "()Ljava/lang/Runnable;", "Lkotlin/coroutines/CoroutineContext;", "context", "block", "dispatch", "(Lkotlin/coroutines/CoroutineContext;Ljava/lang/Runnable;)V", "task", "enqueue", "(Ljava/lang/Runnable;)V", "", "enqueueImpl", "(Ljava/lang/Runnable;)Z", "", "processNextEvent", "()J", "rescheduleAllDelayed", "resetAll", "now", "Lkotlinx/coroutines/EventLoopImplBase$DelayedTask;", "delayedTask", "schedule", "(JLkotlinx/coroutines/EventLoopImplBase$DelayedTask;)V", "", "scheduleImpl", "(JLkotlinx/coroutines/EventLoopImplBase$DelayedTask;)I", "timeMillis", "Lkotlinx/coroutines/DisposableHandle;", "scheduleInvokeOnTimeout", "(JLjava/lang/Runnable;)Lkotlinx/coroutines/DisposableHandle;", "Lkotlinx/coroutines/CancellableContinuation;", "continuation", "scheduleResumeAfterDelay", "(JLkotlinx/coroutines/CancellableContinuation;)V", "shouldUnpark", "(Lkotlinx/coroutines/EventLoopImplBase$DelayedTask;)Z", "shutdown", "value", "isCompleted", "()Z", "setCompleted", "(Z)V", "isEmpty", "getNextTime", "nextTime", "DelayedResumeTask", "DelayedRunnableTask", "DelayedTask", "DelayedTaskQueue", "kotlinx-coroutines-core", "Lkotlinx/coroutines/EventLoopImplPlatform;", "Lkotlinx/coroutines/Delay;"}, k = 1, mv = {1, 6, 0}, xi = 48)
public abstract class EventLoopImplBase extends EventLoopImplPlatform implements Delay {

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public static final /* synthetic */ AtomicReferenceFieldUpdater f9471q = AtomicReferenceFieldUpdater.newUpdater(EventLoopImplBase.class, Object.class, "_queue");

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public static final /* synthetic */ AtomicReferenceFieldUpdater f9472r = AtomicReferenceFieldUpdater.newUpdater(EventLoopImplBase.class, Object.class, "_delayed");
    private volatile /* synthetic */ Object _queue = null;
    private volatile /* synthetic */ Object _delayed = null;
    private volatile /* synthetic */ int _isCompleted = 0;

    /* JADX INFO: renamed from: s.a.r0$a */
    @Metadata(d1 = {"\u0000\"\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010\u0002\n\u0002\b\u0003\n\u0002\u0010\u000e\n\u0000\b\u0082\u0004\u0018\u00002\u00020\u0001B\u001b\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\f\u0010\u0004\u001a\b\u0012\u0004\u0012\u00020\u00060\u0005¢\u0006\u0002\u0010\u0007J\b\u0010\b\u001a\u00020\u0006H\u0016J\b\u0010\t\u001a\u00020\nH\u0016R\u0014\u0010\u0004\u001a\b\u0012\u0004\u0012\u00020\u00060\u0005X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\u000b"}, d2 = {"Lkotlinx/coroutines/EventLoopImplBase$DelayedResumeTask;", "Lkotlinx/coroutines/EventLoopImplBase$DelayedTask;", "nanoTime", "", "cont", "Lkotlinx/coroutines/CancellableContinuation;", "", "(Lkotlinx/coroutines/EventLoopImplBase;JLkotlinx/coroutines/CancellableContinuation;)V", "run", "toString", "", "kotlinx-coroutines-core"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public final class a extends c {

        /* JADX INFO: renamed from: n, reason: collision with root package name */
        public final CancellableContinuation<Unit> f9473n;

        /* JADX WARN: Multi-variable type inference failed */
        public a(long j2, CancellableContinuation<? super Unit> cancellableContinuation) {
            super(j2);
            this.f9473n = cancellableContinuation;
        }

        @Override // java.lang.Runnable
        public void run() {
            this.f9473n.e(EventLoopImplBase.this, Unit.a);
        }

        @Override // s.coroutines.EventLoopImplBase.c
        public String toString() {
            return super.toString() + this.f9473n;
        }
    }

    /* JADX INFO: renamed from: s.a.r0$b */
    @Metadata(d1 = {"\u0000(\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\u000e\n\u0000\b\u0002\u0018\u00002\u00020\u0001B\u0019\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\n\u0010\u0004\u001a\u00060\u0005j\u0002`\u0006¢\u0006\u0002\u0010\u0007J\b\u0010\b\u001a\u00020\tH\u0016J\b\u0010\n\u001a\u00020\u000bH\u0016R\u0012\u0010\u0004\u001a\u00060\u0005j\u0002`\u0006X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006\f"}, d2 = {"Lkotlinx/coroutines/EventLoopImplBase$DelayedRunnableTask;", "Lkotlinx/coroutines/EventLoopImplBase$DelayedTask;", "nanoTime", "", "block", "Ljava/lang/Runnable;", "Lkotlinx/coroutines/Runnable;", "(JLjava/lang/Runnable;)V", "run", "", "toString", "", "kotlinx-coroutines-core"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public static final class b extends c {

        /* JADX INFO: renamed from: n, reason: collision with root package name */
        public final Runnable f9475n;

        public b(long j2, Runnable runnable) {
            super(j2);
            this.f9475n = runnable;
        }

        @Override // java.lang.Runnable
        public void run() {
            this.f9475n.run();
        }

        @Override // s.coroutines.EventLoopImplBase.c
        public String toString() {
            return super.toString() + this.f9475n;
        }
    }

    /* JADX INFO: renamed from: s.a.r0$c */
    @Metadata(d1 = {"\u0000X\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u000f\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0010\b\n\u0002\b\u0007\n\u0002\u0010\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0000\n\u0002\u0010\u000e\n\u0000\b \u0018\u00002\u00060\u0001j\u0002`\u00022\b\u0012\u0004\u0012\u00020\u00000\u00032\u00020\u00042\u00020\u0005B\r\u0012\u0006\u0010\u0006\u001a\u00020\u0007¢\u0006\u0002\u0010\bJ\u0011\u0010\u0018\u001a\u00020\u00132\u0006\u0010\u0019\u001a\u00020\u0000H\u0096\u0002J\u0006\u0010\u001a\u001a\u00020\u001bJ\u001e\u0010\u001c\u001a\u00020\u00132\u0006\u0010\u001d\u001a\u00020\u00072\u0006\u0010\u001e\u001a\u00020\u001f2\u0006\u0010 \u001a\u00020!J\u000e\u0010\"\u001a\u00020#2\u0006\u0010\u001d\u001a\u00020\u0007J\b\u0010$\u001a\u00020%H\u0016R\u0010\u0010\t\u001a\u0004\u0018\u00010\nX\u0082\u000e¢\u0006\u0002\n\u0000R0\u0010\r\u001a\b\u0012\u0002\b\u0003\u0018\u00010\f2\f\u0010\u000b\u001a\b\u0012\u0002\b\u0003\u0018\u00010\f8V@VX\u0096\u000e¢\u0006\f\u001a\u0004\b\u000e\u0010\u000f\"\u0004\b\u0010\u0010\u0011R\u001a\u0010\u0012\u001a\u00020\u0013X\u0096\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0014\u0010\u0015\"\u0004\b\u0016\u0010\u0017R\u0012\u0010\u0006\u001a\u00020\u00078\u0006@\u0006X\u0087\u000e¢\u0006\u0002\n\u0000¨\u0006&"}, d2 = {"Lkotlinx/coroutines/EventLoopImplBase$DelayedTask;", "Ljava/lang/Runnable;", "Lkotlinx/coroutines/Runnable;", "", "Lkotlinx/coroutines/DisposableHandle;", "Lkotlinx/coroutines/internal/ThreadSafeHeapNode;", "nanoTime", "", "(J)V", "_heap", "", "value", "Lkotlinx/coroutines/internal/ThreadSafeHeap;", "heap", "getHeap", "()Lkotlinx/coroutines/internal/ThreadSafeHeap;", "setHeap", "(Lkotlinx/coroutines/internal/ThreadSafeHeap;)V", "index", "", "getIndex", "()I", "setIndex", "(I)V", "compareTo", "other", "dispose", "", "scheduleTask", "now", "delayed", "Lkotlinx/coroutines/EventLoopImplBase$DelayedTaskQueue;", "eventLoop", "Lkotlinx/coroutines/EventLoopImplBase;", "timeToExecute", "", "toString", "", "kotlinx-coroutines-core"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public static abstract class c implements Runnable, Comparable<c>, DisposableHandle, ThreadSafeHeapNode {
        private volatile Object _heap;

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

        /* JADX INFO: renamed from: m, reason: collision with root package name */
        public int f9477m = -1;

        public c(long j2) {
            this.f9476f = j2;
        }

        @Override // s.coroutines.DisposableHandle
        public final synchronized void b() {
            Object obj = this._heap;
            Symbol symbol = t0.a;
            if (obj == symbol) {
                return;
            }
            d dVar = obj instanceof d ? (d) obj : null;
            if (dVar != null) {
                synchronized (dVar) {
                    if (g() != null) {
                        dVar.d(getF9477m());
                    }
                }
            }
            this._heap = symbol;
        }

        @Override // java.lang.Comparable
        public int compareTo(c cVar) {
            long j2 = this.f9476f - cVar.f9476f;
            if (j2 > 0) {
                return 1;
            }
            return j2 < 0 ? -1 : 0;
        }

        @Override // s.coroutines.internal.ThreadSafeHeapNode
        public void e(ThreadSafeHeap<?> threadSafeHeap) {
            if (!(this._heap != t0.a)) {
                throw new IllegalArgumentException("Failed requirement.".toString());
            }
            this._heap = threadSafeHeap;
        }

        @Override // s.coroutines.internal.ThreadSafeHeapNode
        public ThreadSafeHeap<?> g() {
            Object obj = this._heap;
            if (obj instanceof ThreadSafeHeap) {
                return (ThreadSafeHeap) obj;
            }
            return null;
        }

        @Override // s.coroutines.internal.ThreadSafeHeapNode
        /* JADX INFO: renamed from: i, reason: from getter */
        public int getF9477m() {
            return this.f9477m;
        }

        @Override // s.coroutines.internal.ThreadSafeHeapNode
        public void j(int i2) {
            this.f9477m = i2;
        }

        /* JADX WARN: Removed duplicated region for block: B:25:0x003c A[Catch: all -> 0x0045, TryCatch #0 {, blocks: (B:7:0x000a, B:16:0x001f, B:20:0x0029, B:23:0x0033, B:25:0x003c, B:26:0x003e, B:22:0x0031), top: B:37:0x000a, outer: #1 }] */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        public final synchronized int k(long r8, s.coroutines.EventLoopImplBase.d r10, s.coroutines.EventLoopImplBase r11) {
            /*
                r7 = this;
                monitor-enter(r7)
                java.lang.Object r0 = r7._heap     // Catch: java.lang.Throwable -> L48
                s.a.b2.s r1 = s.coroutines.t0.a     // Catch: java.lang.Throwable -> L48
                if (r0 != r1) goto L9
                r8 = 2
                goto L43
            L9:
                monitor-enter(r10)     // Catch: java.lang.Throwable -> L48
                s.a.b2.w r0 = r10.b()     // Catch: java.lang.Throwable -> L45
                s.a.r0$c r0 = (s.coroutines.EventLoopImplBase.c) r0     // Catch: java.lang.Throwable -> L45
                boolean r11 = s.coroutines.EventLoopImplBase.K(r11)     // Catch: java.lang.Throwable -> L45
                if (r11 == 0) goto L1a
                r8 = 1
                monitor-exit(r10)     // Catch: java.lang.Throwable -> L48
                monitor-exit(r7)
                return r8
            L1a:
                r1 = 0
                if (r0 != 0) goto L1f
                goto L31
            L1f:
                long r3 = r0.f9476f     // Catch: java.lang.Throwable -> L45
                long r5 = r3 - r8
                int r11 = (r5 > r1 ? 1 : (r5 == r1 ? 0 : -1))
                if (r11 < 0) goto L28
                goto L29
            L28:
                r8 = r3
            L29:
                long r3 = r10.f9478b     // Catch: java.lang.Throwable -> L45
                long r3 = r8 - r3
                int r11 = (r3 > r1 ? 1 : (r3 == r1 ? 0 : -1))
                if (r11 <= 0) goto L33
            L31:
                r10.f9478b = r8     // Catch: java.lang.Throwable -> L45
            L33:
                long r8 = r7.f9476f     // Catch: java.lang.Throwable -> L45
                long r3 = r10.f9478b     // Catch: java.lang.Throwable -> L45
                long r8 = r8 - r3
                int r8 = (r8 > r1 ? 1 : (r8 == r1 ? 0 : -1))
                if (r8 >= 0) goto L3e
                r7.f9476f = r3     // Catch: java.lang.Throwable -> L45
            L3e:
                r10.a(r7)     // Catch: java.lang.Throwable -> L45
                monitor-exit(r10)     // Catch: java.lang.Throwable -> L48
                r8 = 0
            L43:
                monitor-exit(r7)
                return r8
            L45:
                r8 = move-exception
                monitor-exit(r10)     // Catch: java.lang.Throwable -> L48
                throw r8     // Catch: java.lang.Throwable -> L48
            L48:
                r8 = move-exception
                monitor-exit(r7)
                throw r8
            */
            throw new UnsupportedOperationException("Method not decompiled: s.coroutines.EventLoopImplBase.c.k(long, s.a.r0$d, s.a.r0):int");
        }

        public String toString() {
            StringBuilder sbF = g.a.a.a.a.F("Delayed[nanos=");
            sbF.append(this.f9476f);
            sbF.append(AbstractJsonLexerKt.END_LIST);
            return sbF.toString();
        }
    }

    /* JADX INFO: renamed from: s.a.r0$d */
    @Metadata(d1 = {"\u0000\u0016\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\t\n\u0002\b\u0002\b\u0000\u0018\u00002\b\u0012\u0004\u0012\u00020\u00020\u0001B\r\u0012\u0006\u0010\u0003\u001a\u00020\u0004¢\u0006\u0002\u0010\u0005R\u0012\u0010\u0003\u001a\u00020\u00048\u0006@\u0006X\u0087\u000e¢\u0006\u0002\n\u0000¨\u0006\u0006"}, d2 = {"Lkotlinx/coroutines/EventLoopImplBase$DelayedTaskQueue;", "Lkotlinx/coroutines/internal/ThreadSafeHeap;", "Lkotlinx/coroutines/EventLoopImplBase$DelayedTask;", "timeNow", "", "(J)V", "kotlinx-coroutines-core"}, k = 1, mv = {1, 6, 0}, xi = 48)
    public static final class d extends ThreadSafeHeap<c> {

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

        public d(long j2) {
            this.f9478b = j2;
        }
    }

    /* JADX WARN: Type inference failed for: r0v1, types: [boolean, int] */
    public static final boolean K(EventLoopImplBase eventLoopImplBase) {
        return eventLoopImplBase._isCompleted;
    }

    /* JADX WARN: Removed duplicated region for block: B:59:0x0098  */
    /* JADX WARN: Removed duplicated region for block: B:76:0x00bc  */
    @Override // s.coroutines.EventLoop
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public long G() {
        /*
            Method dump skipped, instruction units count: 218
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: s.coroutines.EventLoopImplBase.G():long");
    }

    public void L(Runnable runnable) {
        if (!M(runnable)) {
            DefaultExecutor.f9425s.L(runnable);
            return;
        }
        Thread threadI = getF9421s();
        if (Thread.currentThread() != threadI) {
            LockSupport.unpark(threadI);
        }
    }

    public final boolean M(Runnable runnable) {
        while (true) {
            Object obj = this._queue;
            if (this._isCompleted != 0) {
                return false;
            }
            if (obj == null) {
                if (f9471q.compareAndSet(this, null, runnable)) {
                    return true;
                }
            } else if (obj instanceof LockFreeTaskQueueCore) {
                LockFreeTaskQueueCore lockFreeTaskQueueCore = (LockFreeTaskQueueCore) obj;
                int iA = lockFreeTaskQueueCore.a(runnable);
                if (iA == 0) {
                    return true;
                }
                if (iA == 1) {
                    f9471q.compareAndSet(this, obj, lockFreeTaskQueueCore.e());
                } else if (iA == 2) {
                    return false;
                }
            } else {
                if (obj == t0.f9479b) {
                    return false;
                }
                LockFreeTaskQueueCore lockFreeTaskQueueCore2 = new LockFreeTaskQueueCore(8, true);
                lockFreeTaskQueueCore2.a((Runnable) obj);
                lockFreeTaskQueueCore2.a(runnable);
                if (f9471q.compareAndSet(this, obj, lockFreeTaskQueueCore2)) {
                    return true;
                }
            }
        }
    }

    public boolean N() {
        ArrayQueue<DispatchedTask<?>> arrayQueue = this.f9470p;
        if (!(arrayQueue == null || arrayQueue.f9329b == arrayQueue.f9330c)) {
            return false;
        }
        d dVar = (d) this._delayed;
        if (dVar != null && !dVar.c()) {
            return false;
        }
        Object obj = this._queue;
        if (obj == null) {
            return true;
        }
        return obj instanceof LockFreeTaskQueueCore ? ((LockFreeTaskQueueCore) obj).d() : obj == t0.f9479b;
    }

    public final void O() {
        this._queue = null;
        this._delayed = null;
    }

    public final void P(long j2, c cVar) {
        int iK;
        Thread threadI;
        c cVarB;
        c cVar2 = null;
        if (this._isCompleted != 0) {
            iK = 1;
        } else {
            d dVar = (d) this._delayed;
            if (dVar == null) {
                f9472r.compareAndSet(this, null, new d(j2));
                Object obj = this._delayed;
                o.c(obj);
                dVar = (d) obj;
            }
            iK = cVar.k(j2, dVar, this);
        }
        if (iK != 0) {
            if (iK == 1) {
                J(j2, cVar);
                return;
            } else {
                if (iK != 2) {
                    throw new IllegalStateException("unexpected result".toString());
                }
                return;
            }
        }
        d dVar2 = (d) this._delayed;
        if (dVar2 != null) {
            synchronized (dVar2) {
                cVarB = dVar2.b();
            }
            cVar2 = cVarB;
        }
        if (!(cVar2 == cVar) || Thread.currentThread() == (threadI = getF9421s())) {
            return;
        }
        LockSupport.unpark(threadI);
    }

    @Override // s.coroutines.Delay
    public void e(long j2, CancellableContinuation<? super Unit> cancellableContinuation) {
        long jA = t0.a(j2);
        if (jA < 4611686018427387903L) {
            long jNanoTime = System.nanoTime();
            a aVar = new a(jA + jNanoTime, cancellableContinuation);
            P(jNanoTime, aVar);
            cancellableContinuation.b(new DisposeOnCancel(aVar));
        }
    }

    public DisposableHandle l(long j2, Runnable runnable, CoroutineContext coroutineContext) {
        return g0.f9427b.l(j2, runnable, coroutineContext);
    }

    @Override // s.coroutines.EventLoop
    public void shutdown() {
        c cVarE;
        ThreadLocalEventLoop threadLocalEventLoop = ThreadLocalEventLoop.a;
        ThreadLocalEventLoop.f9480b.set(null);
        this._isCompleted = 1;
        while (true) {
            Object obj = this._queue;
            if (obj == null) {
                if (f9471q.compareAndSet(this, null, t0.f9479b)) {
                    break;
                }
            } else if (obj instanceof LockFreeTaskQueueCore) {
                ((LockFreeTaskQueueCore) obj).b();
                break;
            } else {
                if (obj == t0.f9479b) {
                    break;
                }
                LockFreeTaskQueueCore lockFreeTaskQueueCore = new LockFreeTaskQueueCore(8, true);
                lockFreeTaskQueueCore.a((Runnable) obj);
                if (f9471q.compareAndSet(this, obj, lockFreeTaskQueueCore)) {
                    break;
                }
            }
        }
        while (G() <= 0) {
        }
        long jNanoTime = System.nanoTime();
        while (true) {
            d dVar = (d) this._delayed;
            if (dVar == null || (cVarE = dVar.e()) == null) {
                return;
            } else {
                J(jNanoTime, cVarE);
            }
        }
    }

    @Override // s.coroutines.CoroutineDispatcher
    public final void z(CoroutineContext coroutineContext, Runnable runnable) {
        L(runnable);
    }
}
