package kotlinx.coroutines;

import kotlin.Pair;
import kotlin.coroutines.Continuation;

/* JADX INFO: loaded from: classes.dex */
public final class t1 extends kotlinx.coroutines.internal.r {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final ThreadLocal f29563e;
    private volatile boolean threadLocalIsSet;

    /* JADX WARN: Illegal instructions before constructor call */
    public t1(Continuation continuation, kotlin.coroutines.h hVar) {
        u1 u1Var = u1.f29567a;
        super(continuation, hVar.m(u1Var) == null ? hVar.p(u1Var) : hVar);
        this.f29563e = new ThreadLocal();
        if (continuation.getContext().m(kotlin.coroutines.c.f29225a) instanceof t) {
            return;
        }
        Object objC = kotlinx.coroutines.internal.v.c(hVar, null);
        kotlinx.coroutines.internal.v.a(hVar, objC);
        c0(hVar, objC);
    }

    public final boolean b0() {
        boolean z10 = this.threadLocalIsSet && this.f29563e.get() == null;
        this.f29563e.remove();
        return !z10;
    }

    public final void c0(kotlin.coroutines.h hVar, Object obj) {
        this.threadLocalIsSet = true;
        this.f29563e.set(new Pair(hVar, obj));
    }

    @Override // kotlinx.coroutines.internal.r, kotlinx.coroutines.g1
    public final void o(Object obj) {
        if (this.threadLocalIsSet) {
            Pair pair = (Pair) this.f29563e.get();
            if (pair != null) {
                kotlinx.coroutines.internal.v.a((kotlin.coroutines.h) pair.getFirst(), pair.getSecond());
            }
            this.f29563e.remove();
        }
        Object objK = nb.g.K(obj);
        Continuation continuation = this.f29485d;
        kotlin.coroutines.h context = continuation.getContext();
        Object objC = kotlinx.coroutines.internal.v.c(context, null);
        t1 t1VarH0 = objC != kotlinx.coroutines.internal.v.f29490a ? y.h0(continuation, context, objC) : null;
        try {
            this.f29485d.resumeWith(objK);
        } finally {
            if (t1VarH0 == null || t1VarH0.b0()) {
                kotlinx.coroutines.internal.v.a(context, objC);
            }
        }
    }
}
