package kotlinx.coroutines;

import java.util.concurrent.locks.LockSupport;

/* JADX INFO: compiled from: Builders.kt */
/* JADX INFO: loaded from: classes.dex */
final class g<T> extends c<T> {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private final Thread f1078f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private final f1 f1079g;

    public g(h.u.g gVar, Thread thread, f1 f1Var) {
        super(gVar, true, true);
        this.f1078f = thread;
        this.f1079g = f1Var;
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final T H0() throws Throwable {
        d dVarA = e.a();
        if (dVarA != null) {
            dVarA.c();
        }
        try {
            f1 f1Var = this.f1079g;
            if (f1Var != null) {
                f1.T(f1Var, false, 1, null);
            }
            while (!Thread.interrupted()) {
                try {
                    f1 f1Var2 = this.f1079g;
                    long jW = f1Var2 == null ? Long.MAX_VALUE : f1Var2.W();
                    if (c0()) {
                        T t = (T) a2.h(X());
                        b0Var = t instanceof b0 ? (b0) t : null;
                        if (b0Var == null) {
                            return t;
                        }
                        throw b0Var.a;
                    }
                    d dVarA2 = e.a();
                    if (dVarA2 == null) {
                        LockSupport.parkNanos(this, jW);
                    } else {
                        dVarA2.b(this, jW);
                    }
                } finally {
                    f1 f1Var3 = this.f1079g;
                    if (f1Var3 != null) {
                        f1.N(f1Var3, false, 1, null);
                    }
                }
            }
            InterruptedException interruptedException = new InterruptedException();
            E(interruptedException);
            throw interruptedException;
        } finally {
            d dVarA3 = e.a();
            if (dVarA3 != null) {
                dVarA3.g();
            }
        }
    }

    @Override // kotlinx.coroutines.z1
    protected boolean d0() {
        return true;
    }

    @Override // kotlinx.coroutines.z1
    protected void w(Object obj) {
        if (h.x.d.k.a(Thread.currentThread(), this.f1078f)) {
            return;
        }
        Thread thread = this.f1078f;
        d dVarA = e.a();
        if (dVarA == null) {
            LockSupport.unpark(thread);
        } else {
            dVarA.f(thread);
        }
    }
}
