package kotlinx.coroutines.internal;

import F1.AbstractC0110a0;
import F1.C;
import F1.C0132m;
import F1.C0144z;
import F1.E;
import F1.G0;
import F1.InterfaceC0131l;
import F1.L;
import F1.U;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/* JADX INFO: loaded from: classes.dex */
public final class e extends U implements kotlin.coroutines.jvm.internal.e, q1.d {

    /* JADX INFO: renamed from: L, reason: collision with root package name */
    private static final /* synthetic */ AtomicReferenceFieldUpdater f5146L = AtomicReferenceFieldUpdater.newUpdater(e.class, Object.class, "_reusableCancellableContinuation");

    /* JADX INFO: renamed from: H, reason: collision with root package name */
    public Object f5147H;

    /* JADX INFO: renamed from: I, reason: collision with root package name */
    public final Object f5148I;
    private volatile /* synthetic */ Object _reusableCancellableContinuation;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public final E f5149x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final q1.d f5150y;

    public e(E e2, q1.d dVar) {
        super(-1);
        this.f5149x = e2;
        this.f5150y = dVar;
        this.f5147H = f.f5151a;
        this.f5148I = v.b(getContext());
        this._reusableCancellableContinuation = null;
    }

    private final C0132m j() {
        Object obj = this._reusableCancellableContinuation;
        if (obj instanceof C0132m) {
            return (C0132m) obj;
        }
        return null;
    }

    @Override // F1.U
    public void a(Object obj, Throwable th) {
        if (obj instanceof C0144z) {
            ((C0144z) obj).f669b.invoke(th);
        }
    }

    @Override // F1.U
    public q1.d c() {
        return this;
    }

    @Override // kotlin.coroutines.jvm.internal.e
    public kotlin.coroutines.jvm.internal.e getCallerFrame() {
        q1.d dVar = this.f5150y;
        if (dVar instanceof kotlin.coroutines.jvm.internal.e) {
            return (kotlin.coroutines.jvm.internal.e) dVar;
        }
        return null;
    }

    @Override // q1.d
    public q1.g getContext() {
        return this.f5150y.getContext();
    }

    @Override // F1.U
    public Object h() {
        Object obj = this.f5147H;
        this.f5147H = f.f5151a;
        return obj;
    }

    public final void i() {
        while (this._reusableCancellableContinuation == f.f5152b) {
        }
    }

    public final boolean k() {
        return this._reusableCancellableContinuation != null;
    }

    public final boolean l(Throwable th) {
        while (true) {
            Object obj = this._reusableCancellableContinuation;
            r rVar = f.f5152b;
            if (kotlin.jvm.internal.l.a(obj, rVar)) {
                if (androidx.concurrent.futures.a.a(f5146L, this, rVar, th)) {
                    return true;
                }
            } else {
                if (obj instanceof Throwable) {
                    return true;
                }
                if (androidx.concurrent.futures.a.a(f5146L, this, obj, null)) {
                    return false;
                }
            }
        }
    }

    public final void m() {
        i();
        C0132m c0132mJ = j();
        if (c0132mJ == null) {
            return;
        }
        c0132mJ.o();
    }

    public final Throwable n(InterfaceC0131l interfaceC0131l) {
        r rVar;
        do {
            Object obj = this._reusableCancellableContinuation;
            rVar = f.f5152b;
            if (obj != rVar) {
                if (!(obj instanceof Throwable)) {
                    throw new IllegalStateException(kotlin.jvm.internal.l.l("Inconsistent state ", obj).toString());
                }
                if (androidx.concurrent.futures.a.a(f5146L, this, obj, null)) {
                    return (Throwable) obj;
                }
                throw new IllegalArgumentException("Failed requirement.");
            }
        } while (!androidx.concurrent.futures.a.a(f5146L, this, rVar, interfaceC0131l));
        return null;
    }

    @Override // q1.d
    public void resumeWith(Object obj) {
        q1.g context = this.f5150y.getContext();
        Object objD = C.d(obj, null, 1, null);
        if (this.f5149x.v(context)) {
            this.f5147H = objD;
            this.f591r = 0;
            this.f5149x.u(context, this);
            return;
        }
        AbstractC0110a0 abstractC0110a0B = G0.f579a.b();
        if (abstractC0110a0B.H()) {
            this.f5147H = objD;
            this.f591r = 0;
            abstractC0110a0B.C(this);
            return;
        }
        abstractC0110a0B.F(true);
        try {
            q1.g context2 = getContext();
            Object objC = v.c(context2, this.f5148I);
            try {
                this.f5150y.resumeWith(obj);
                n1.s sVar = n1.s.f5871a;
                while (abstractC0110a0B.L()) {
                }
            } finally {
                v.a(context2, objC);
            }
        } finally {
            try {
            } finally {
            }
        }
    }

    public String toString() {
        return "DispatchedContinuation[" + this.f5149x + ", " + L.c(this.f5150y) + ']';
    }
}
