package kotlinx.coroutines.internal;

import com.google.android.gms.common.api.internal.v0;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import kotlinx.coroutines.a0;
import kotlinx.coroutines.d0;
import kotlinx.coroutines.j0;
import kotlinx.coroutines.r1;

/* JADX INFO: loaded from: classes.dex */
public final class h extends kotlinx.coroutines.t implements d0 {

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public static final /* synthetic */ AtomicIntegerFieldUpdater f29465h = AtomicIntegerFieldUpdater.newUpdater(h.class, "runningWorkers$volatile");

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final kotlinx.coroutines.t f29466c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final int f29467d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final /* synthetic */ d0 f29468e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final j f29469f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final Object f29470g;
    private volatile /* synthetic */ int runningWorkers$volatile;

    /* JADX WARN: Multi-variable type inference failed */
    public h(kotlinx.coroutines.t tVar, int i10) {
        this.f29466c = tVar;
        this.f29467d = i10;
        d0 d0Var = tVar instanceof d0 ? (d0) tVar : null;
        this.f29468e = d0Var == null ? a0.f29290a : d0Var;
        this.f29469f = new j();
        this.f29470g = new Object();
    }

    @Override // kotlinx.coroutines.t
    public final void L(kotlin.coroutines.h hVar, Runnable runnable) {
        this.f29469f.a(runnable);
        AtomicIntegerFieldUpdater atomicIntegerFieldUpdater = f29465h;
        if (atomicIntegerFieldUpdater.get(this) < this.f29467d) {
            synchronized (this.f29470g) {
                if (atomicIntegerFieldUpdater.get(this) >= this.f29467d) {
                    return;
                }
                atomicIntegerFieldUpdater.incrementAndGet(this);
                Runnable runnableO = O();
                if (runnableO == null) {
                    return;
                }
                this.f29466c.L(this, new v0(this, runnableO, 15));
            }
        }
    }

    @Override // kotlinx.coroutines.t
    public final kotlinx.coroutines.t N(int i10) {
        kotlinx.coroutines.y.e(1);
        return 1 >= this.f29467d ? this : super.N(1);
    }

    public final Runnable O() {
        while (true) {
            Runnable runnable = (Runnable) this.f29469f.d();
            if (runnable != null) {
                return runnable;
            }
            synchronized (this.f29470g) {
                AtomicIntegerFieldUpdater atomicIntegerFieldUpdater = f29465h;
                atomicIntegerFieldUpdater.decrementAndGet(this);
                if (this.f29469f.c() == 0) {
                    return null;
                }
                atomicIntegerFieldUpdater.incrementAndGet(this);
            }
        }
    }

    @Override // kotlinx.coroutines.d0
    public final j0 k(long j10, r1 r1Var, kotlin.coroutines.h hVar) {
        return this.f29468e.k(j10, r1Var, hVar);
    }
}
