package kotlinx.coroutines.internal;

import d2.n1;
import d2.o0;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/* JADX INFO: compiled from: DispatchedContinuation.kt */
/* JADX INFO: loaded from: classes.dex */
public final class f<T> extends d2.j0<T> implements p1.d, n1.d<T> {
    private volatile /* synthetic */ Object _reusableCancellableContinuation;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final d2.u f5183h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final n1.d<T> f5184i;

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

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final Object f5186k;

    static {
        AtomicReferenceFieldUpdater.newUpdater(f.class, Object.class, "_reusableCancellableContinuation");
    }

    /* JADX WARN: Multi-variable type inference failed */
    public f(d2.u uVar, n1.d<? super T> dVar) {
        super(-1);
        this.f5183h = uVar;
        this.f5184i = dVar;
        this.f5185j = g.f5194a;
        this.f5186k = f0.b(d());
        this._reusableCancellableContinuation = null;
    }

    private final d2.h<?> k() {
        Object obj = this._reusableCancellableContinuation;
        if (obj instanceof d2.h) {
            return (d2.h) obj;
        }
        return null;
    }

    @Override // d2.j0
    public void a(Object obj, Throwable th) {
        if (obj instanceof d2.o) {
            ((d2.o) obj).f4513b.e(th);
        }
    }

    @Override // d2.j0
    public n1.d<T> b() {
        return this;
    }

    @Override // n1.d
    public n1.f d() {
        return this.f5184i.d();
    }

    @Override // p1.d
    public p1.d g() {
        n1.d<T> dVar = this.f5184i;
        if (dVar instanceof p1.d) {
            return (p1.d) dVar;
        }
        return null;
    }

    @Override // d2.j0
    public Object h() {
        Object obj = this.f5185j;
        if (d2.c0.a()) {
            if (!(obj != g.f5194a)) {
                throw new AssertionError();
            }
        }
        this.f5185j = g.f5194a;
        return obj;
    }

    public final void i() {
        while (this._reusableCancellableContinuation == g.f5195b) {
        }
    }

    @Override // n1.d
    public void j(Object obj) {
        n1.f fVarD = this.f5184i.d();
        Object objD = d2.r.d(obj, null, 1, null);
        if (this.f5183h.g(fVarD)) {
            this.f5185j = objD;
            this.f4498g = 0;
            this.f5183h.d(fVarD, this);
            return;
        }
        d2.c0.a();
        o0 o0VarA = n1.f4510a.a();
        if (o0VarA.t()) {
            this.f5185j = objD;
            this.f4498g = 0;
            o0VarA.p(this);
            return;
        }
        o0VarA.r(true);
        try {
            n1.f fVarD2 = d();
            Object objC = f0.c(fVarD2, this.f5186k);
            try {
                this.f5184i.j(obj);
                k1.o oVar = k1.o.f5171a;
                while (o0VarA.v()) {
                }
            } finally {
                f0.a(fVarD2, objC);
            }
        } finally {
            try {
            } finally {
            }
        }
    }

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

    public final void m() {
        i();
        d2.h<?> hVarK = k();
        if (hVarK == null) {
            return;
        }
        hVarK.m();
    }

    @Override // p1.d
    public StackTraceElement n() {
        return null;
    }

    public String toString() {
        return "DispatchedContinuation[" + this.f5183h + ", " + d2.d0.c(this.f5184i) + ']';
    }
}
