package kotlinx.coroutines.scheduling;

import F1.AbstractC0120f0;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;

/* JADX INFO: loaded from: classes2.dex */
final class e extends AbstractC0120f0 implements j, Executor {

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

    /* JADX INFO: renamed from: H, reason: collision with root package name */
    private final int f5217H;

    /* JADX INFO: renamed from: I, reason: collision with root package name */
    private final ConcurrentLinkedQueue f5218I = new ConcurrentLinkedQueue();
    private volatile /* synthetic */ int inFlightTasks = 0;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    private final c f5219r;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    private final int f5220x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    private final String f5221y;

    public e(c cVar, int i2, String str, int i3) {
        this.f5219r = cVar;
        this.f5220x = i2;
        this.f5221y = str;
        this.f5217H = i3;
    }

    private final void w(Runnable runnable, boolean z2) {
        do {
            AtomicIntegerFieldUpdater atomicIntegerFieldUpdater = f5216L;
            if (atomicIntegerFieldUpdater.incrementAndGet(this) <= this.f5220x) {
                this.f5219r.z(runnable, this, z2);
                return;
            }
            this.f5218I.add(runnable);
            if (atomicIntegerFieldUpdater.decrementAndGet(this) >= this.f5220x) {
                return;
            } else {
                runnable = (Runnable) this.f5218I.poll();
            }
        } while (runnable != null);
    }

    @Override // kotlinx.coroutines.scheduling.j
    public void b() {
        Runnable runnable = (Runnable) this.f5218I.poll();
        if (runnable != null) {
            this.f5219r.z(runnable, this, true);
            return;
        }
        f5216L.decrementAndGet(this);
        Runnable runnable2 = (Runnable) this.f5218I.poll();
        if (runnable2 == null) {
            return;
        }
        w(runnable2, true);
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        throw new IllegalStateException("Close cannot be invoked on LimitingBlockingDispatcher");
    }

    @Override // java.util.concurrent.Executor
    public void execute(Runnable runnable) {
        w(runnable, false);
    }

    @Override // kotlinx.coroutines.scheduling.j
    public int i() {
        return this.f5217H;
    }

    @Override // F1.E
    public String toString() {
        String str = this.f5221y;
        if (str != null) {
            return str;
        }
        return super.toString() + "[dispatcher = " + this.f5219r + ']';
    }

    @Override // F1.E
    public void u(q1.g gVar, Runnable runnable) {
        w(runnable, false);
    }
}
