package kotlinx.coroutines.internal;

/* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
/* JADX INFO: loaded from: E:\ios\vf_dex\classes3.dex */
@kotlin.Metadata(d1 = {"\u0000v\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\u0010\u0003\n\u0002\b\u0005\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010\u000e\n\u0002\b\u0015\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0000\u0018\u0000*\u0006\b\u0000\u0010\u0001 \u00002\b\u0012\u0004\u0012\u00028\u00000\u00022\u00060\u0003j\u0002`\u00042\b\u0012\u0004\u0012\u00028\u00000\u0005B\u001d\u0012\u0006\u0010\u0007\u001a\u00020\u0006\u0012\f\u0010\b\u001a\b\u0012\u0004\u0012\u00028\u00000\u0005¢\u0006\u0004\b\t\u0010\nJ\u0017\u0010\r\u001a\n\u0018\u00010\u000bj\u0004\u0018\u0001`\fH\u0016¢\u0006\u0004\b\r\u0010\u000eJ\u000f\u0010\u0010\u001a\u00020\u000fH\u0000¢\u0006\u0004\b\u0010\u0010\u0011J\u000f\u0010\u0013\u001a\u00020\u0012H\u0000¢\u0006\u0004\b\u0013\u0010\u0014J\u000f\u0010\u0015\u001a\u00020\u0012H\u0000¢\u0006\u0004\b\u0015\u0010\u0014J\u0017\u0010\u0017\u001a\n\u0012\u0004\u0012\u00028\u0000\u0018\u00010\u0016H\u0000¢\u0006\u0004\b\u0017\u0010\u0018J\u001d\u0010\u001b\u001a\u0004\u0018\u00010\u001a2\n\u0010\b\u001a\u0006\u0012\u0002\b\u00030\u0019H\u0000¢\u0006\u0004\b\u001b\u0010\u001cJ\u0017\u0010\u001e\u001a\u00020\u000f2\u0006\u0010\u001d\u001a\u00020\u001aH\u0000¢\u0006\u0004\b\u001e\u0010\u001fJ\u0011\u0010!\u001a\u0004\u0018\u00010 H\u0010¢\u0006\u0004\b!\u0010\"J\u001d\u0010%\u001a\u00020\u00122\f\u0010$\u001a\b\u0012\u0004\u0012\u00028\u00000#H\u0016¢\u0006\u0004\b%\u0010&J\u001f\u0010*\u001a\u00020\u00122\u0006\u0010(\u001a\u00020'2\u0006\u0010)\u001a\u00028\u0000H\u0000¢\u0006\u0004\b*\u0010+J\u000f\u0010-\u001a\u00020,H\u0016¢\u0006\u0004\b-\u0010.R\u0014\u0010\u0007\u001a\u00020\u00068\u0000X\u0081\u0004¢\u0006\u0006\n\u0004\b/\u00100R\u001a\u0010\b\u001a\b\u0012\u0004\u0012\u00028\u00000\u00058\u0006X\u0087\u0004¢\u0006\u0006\n\u0004\b1\u00102R\u001e\u00106\u001a\u0004\u0018\u00010 8\u0000@\u0000X\u0081\u000e¢\u0006\f\n\u0004\b3\u00104\u0012\u0004\b5\u0010\u0014R\u0014\u00107\u001a\u00020 8\u0000X\u0081\u0004¢\u0006\u0006\n\u0004\b!\u00104R\u001a\u00109\u001a\b\u0012\u0002\b\u0003\u0018\u00010\u00168BX\u0082\u0004¢\u0006\u0006\u001a\u0004\b8\u0010\u0018R\u001c\u0010<\u001a\n\u0018\u00010\u0003j\u0004\u0018\u0001`\u00048VX\u0096\u0004¢\u0006\u0006\u001a\u0004\b:\u0010;R\u001a\u0010?\u001a\b\u0012\u0004\u0012\u00028\u00000\u00058PX\u0090\u0004¢\u0006\u0006\u001a\u0004\b=\u0010>R\u0014\u0010(\u001a\u00020'8\u0016X\u0096\u0005¢\u0006\u0006\u001a\u0004\b@\u0010AR\u0013\u0010C\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010 0B8\u0002X\u0082\u0004¨\u0006D"}, d2 = {"Lkotlinx/coroutines/internal/DispatchedContinuation;", "T", "Lkotlinx/coroutines/DispatchedTask;", "Lkotlin/coroutines/jvm/internal/CoroutineStackFrame;", "Lkotlinx/coroutines/internal/CoroutineStackFrame;", "Lkotlin/coroutines/Continuation;", "Lkotlinx/coroutines/CoroutineDispatcher;", "dispatcher", "continuation", "<init>", "(Lkotlinx/coroutines/CoroutineDispatcher;Lkotlin/coroutines/Continuation;)V", "Ljava/lang/StackTraceElement;", "Lkotlinx/coroutines/internal/StackTraceElement;", "getStackTraceElement", "()Ljava/lang/StackTraceElement;", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "m", "()Z", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "h", "()V", "o", "Lkotlinx/coroutines/CancellableContinuationImpl;", "i", "()Lkotlinx/coroutines/CancellableContinuationImpl;", "Lkotlinx/coroutines/CancellableContinuation;", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "p", "(Lkotlinx/coroutines/CancellableContinuation;)Ljava/lang/Throwable;", "cause", "n", "(Ljava/lang/Throwable;)Z", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "g", "()Ljava/lang/Object;", "Lkotlin/Result;", "result", "resumeWith", "(Ljava/lang/Object;)V", "Lkotlin/coroutines/CoroutineContext;", "context", "value", "j", "(Lkotlin/coroutines/CoroutineContext;Ljava/lang/Object;)V", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "toString", "()Ljava/lang/String;", "d", "Lkotlinx/coroutines/CoroutineDispatcher;", "e", "Lkotlin/coroutines/Continuation;", "f", "Ljava/lang/Object;", "get_state$kotlinx_coroutines_core$annotations", "_state", "countOrElement", "k", "reusableCancellableContinuation", "getCallerFrame", "()Lkotlin/coroutines/jvm/internal/CoroutineStackFrame;", "callerFrame", "c", "()Lkotlin/coroutines/Continuation;", "delegate", "getContext", "()Lkotlin/coroutines/CoroutineContext;", "Lkotlinx/atomicfu/AtomicRef;", "_reusableCancellableContinuation", "kotlinx-coroutines-core"}, k = 1, mv = {2, 1, 0}, xi = 48)
@kotlin.jvm.internal.SourceDebugExtension
public final class DispatchedContinuation<T> extends kotlinx.coroutines.DispatchedTask<T> implements kotlin.coroutines.jvm.internal.CoroutineStackFrame, kotlin.coroutines.Continuation<T> {
    private static final /* synthetic */ java.util.concurrent.atomic.AtomicReferenceFieldUpdater h = java.util.concurrent.atomic.AtomicReferenceFieldUpdater.newUpdater(kotlinx.coroutines.internal.DispatchedContinuation.class, java.lang.Object.class, "_reusableCancellableContinuation$volatile");
    private volatile /* synthetic */ java.lang.Object _reusableCancellableContinuation$volatile;

    /* JADX INFO: renamed from: d, reason: from kotlin metadata */
    public final kotlinx.coroutines.CoroutineDispatcher dispatcher;

    /* JADX INFO: renamed from: e, reason: from kotlin metadata */
    public final kotlin.coroutines.Continuation continuation;

    /* JADX INFO: renamed from: f, reason: from kotlin metadata */
    public java.lang.Object _state;

    /* JADX INFO: renamed from: g, reason: from kotlin metadata */
    public final java.lang.Object countOrElement;

    public DispatchedContinuation(kotlinx.coroutines.CoroutineDispatcher coroutineDispatcher, kotlin.coroutines.Continuation continuation) {
        super(-1);
        this.dispatcher = coroutineDispatcher;
        this.continuation = continuation;
        this._state = kotlinx.coroutines.internal.DispatchedContinuationKt.a;
        this.countOrElement = kotlinx.coroutines.internal.ThreadContextKt.g(getContext());
    }

    private final kotlinx.coroutines.CancellableContinuationImpl k() {
        java.lang.Object obj = h.get(this);
        if (obj instanceof kotlinx.coroutines.CancellableContinuationImpl) {
            return (kotlinx.coroutines.CancellableContinuationImpl) obj;
        }
        return null;
    }

    public java.lang.Object g() {
        java.lang.Object obj = this._state;
        this._state = kotlinx.coroutines.internal.DispatchedContinuationKt.a;
        return obj;
    }

    public kotlin.coroutines.jvm.internal.CoroutineStackFrame getCallerFrame() {
        kotlin.coroutines.jvm.internal.CoroutineStackFrame coroutineStackFrame = this.continuation;
        if (coroutineStackFrame instanceof kotlin.coroutines.jvm.internal.CoroutineStackFrame) {
            return coroutineStackFrame;
        }
        return null;
    }

    public kotlin.coroutines.CoroutineContext getContext() {
        return this.continuation.getContext();
    }

    public java.lang.StackTraceElement getStackTraceElement() {
        return null;
    }

    public final void h() {
        while (h.get(this) == kotlinx.coroutines.internal.DispatchedContinuationKt.b) {
        }
    }

    public final kotlinx.coroutines.CancellableContinuationImpl i() {
        java.util.concurrent.atomic.AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = h;
        while (true) {
            java.lang.Object obj = atomicReferenceFieldUpdater.get(this);
            if (obj == null) {
                h.set(this, kotlinx.coroutines.internal.DispatchedContinuationKt.b);
                return null;
            }
            if (obj instanceof kotlinx.coroutines.CancellableContinuationImpl) {
                if (androidx.concurrent.futures.a.a(h, this, obj, kotlinx.coroutines.internal.DispatchedContinuationKt.b)) {
                    return (kotlinx.coroutines.CancellableContinuationImpl) obj;
                }
            } else if (obj != kotlinx.coroutines.internal.DispatchedContinuationKt.b && !(obj instanceof java.lang.Throwable)) {
                throw new java.lang.IllegalStateException(("Inconsistent state " + obj).toString());
            }
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final void j(kotlin.coroutines.CoroutineContext context, java.lang.Object value) {
        this._state = value;
        ((kotlinx.coroutines.DispatchedTask) this).c = 1;
        this.dispatcher.P0(context, this);
    }

    public final boolean m() {
        return h.get(this) != null;
    }

    public final boolean n(java.lang.Throwable cause) {
        java.util.concurrent.atomic.AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = h;
        while (true) {
            java.lang.Object obj = atomicReferenceFieldUpdater.get(this);
            kotlinx.coroutines.internal.Symbol symbol = kotlinx.coroutines.internal.DispatchedContinuationKt.b;
            if (kotlin.jvm.internal.Intrinsics.g(obj, symbol)) {
                if (androidx.concurrent.futures.a.a(h, this, symbol, cause)) {
                    return true;
                }
            } else {
                if (obj instanceof java.lang.Throwable) {
                    return true;
                }
                if (androidx.concurrent.futures.a.a(h, this, obj, (java.lang.Object) null)) {
                    return false;
                }
            }
        }
    }

    public final void o() {
        h();
        kotlinx.coroutines.CancellableContinuationImpl cancellableContinuationImplK = k();
        if (cancellableContinuationImplK != null) {
            cancellableContinuationImplK.n();
        }
    }

    public final java.lang.Throwable p(kotlinx.coroutines.CancellableContinuation continuation) {
        kotlinx.coroutines.internal.Symbol symbol;
        java.util.concurrent.atomic.AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = h;
        do {
            java.lang.Object obj = atomicReferenceFieldUpdater.get(this);
            symbol = kotlinx.coroutines.internal.DispatchedContinuationKt.b;
            if (obj != symbol) {
                if (obj instanceof java.lang.Throwable) {
                    if (androidx.concurrent.futures.a.a(h, this, obj, (java.lang.Object) null)) {
                        return (java.lang.Throwable) obj;
                    }
                    throw new java.lang.IllegalArgumentException("Failed requirement.");
                }
                throw new java.lang.IllegalStateException(("Inconsistent state " + obj).toString());
            }
        } while (!androidx.concurrent.futures.a.a(h, this, symbol, continuation));
        return null;
    }

    /* JADX INFO: Thrown type has an unknown type hierarchy: kotlinx.coroutines.DispatchException */
    /* JADX WARN: Multi-variable type inference failed */
    public void resumeWith(java.lang.Object result) throws kotlinx.coroutines.DispatchException {
        java.lang.Object objB = kotlinx.coroutines.CompletionStateKt.b(result);
        if (kotlinx.coroutines.internal.DispatchedContinuationKt.d(this.dispatcher, getContext())) {
            this._state = objB;
            ((kotlinx.coroutines.DispatchedTask) this).c = 0;
            kotlinx.coroutines.internal.DispatchedContinuationKt.c(this.dispatcher, getContext(), this);
            return;
        }
        kotlinx.coroutines.EventLoop eventLoopB = kotlinx.coroutines.ThreadLocalEventLoop.a.b();
        if (eventLoopB.d2()) {
            this._state = objB;
            ((kotlinx.coroutines.DispatchedTask) this).c = 0;
            eventLoopB.X1(this);
            return;
        }
        eventLoopB.a2(true);
        try {
            kotlin.coroutines.CoroutineContext context = getContext();
            java.lang.Object objI = kotlinx.coroutines.internal.ThreadContextKt.i(context, this.countOrElement);
            try {
                this.continuation.resumeWith(result);
                kotlin.Unit unit = kotlin.Unit.a;
                kotlinx.coroutines.internal.ThreadContextKt.f(context, objI);
                while (eventLoopB.s2()) {
                }
            } catch (java.lang.Throwable th) {
                kotlinx.coroutines.internal.ThreadContextKt.f(context, objI);
                throw th;
            }
        } catch (java.lang.Throwable th2) {
            try {
                f(th2);
            } finally {
                eventLoopB.N1(true);
            }
        }
    }

    public java.lang.String toString() {
        return "DispatchedContinuation[" + this.dispatcher + ", " + kotlinx.coroutines.DebugStringsKt.c(this.continuation) + ']';
    }

    public kotlin.coroutines.Continuation c() {
        return this;
    }
}
