package g.a.n2;

import g.a.o0;
import g.a.r0;

/* JADX INFO: compiled from: LimitedDispatcher.kt */
/* JADX INFO: loaded from: classes.dex */
public final class l extends g.a.b0 implements Runnable, r0 {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private final g.a.b0 f4082f;

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private final /* synthetic */ r0 f4084h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    private final q<Runnable> f4085i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    private final Object f4086j;
    private volatile int runningWorkers;

    /* JADX WARN: Multi-variable type inference failed */
    public l(g.a.b0 b0Var, int i2) {
        this.f4082f = b0Var;
        this.f4083g = i2;
        r0 r0Var = b0Var instanceof r0 ? (r0) b0Var : null;
        this.f4084h = r0Var == null ? o0.a() : r0Var;
        this.f4085i = new q<>(false);
        this.f4086j = new Object();
    }

    private final boolean B(Runnable runnable) {
        this.f4085i.a(runnable);
        return this.runningWorkers >= this.f4083g;
    }

    private final boolean C() {
        synchronized (this.f4086j) {
            if (this.runningWorkers >= this.f4083g) {
                return false;
            }
            this.runningWorkers++;
            return true;
        }
    }

    @Override // g.a.r0
    public void h(long j2, g.a.j<? super f.t> jVar) {
        this.f4084h.h(j2, jVar);
    }

    /* JADX WARN: Code restructure failed: missing block: B:16:0x002a, code lost:
    
        r1 = r4.f4086j;
     */
    /* JADX WARN: Code restructure failed: missing block: B:17:0x002c, code lost:
    
        monitor-enter(r1);
     */
    /* JADX WARN: Code restructure failed: missing block: B:18:0x002d, code lost:
    
        r4.runningWorkers--;
     */
    /* JADX WARN: Code restructure failed: missing block: B:19:0x0039, code lost:
    
        if (r4.f4085i.c() != 0) goto L22;
     */
    /* JADX WARN: Code restructure failed: missing block: B:20:0x003b, code lost:
    
        monitor-exit(r1);
     */
    /* JADX WARN: Code restructure failed: missing block: B:21:0x003c, code lost:
    
        return;
     */
    /* JADX WARN: Code restructure failed: missing block: B:22:0x003d, code lost:
    
        r4.runningWorkers++;
        r2 = f.t.a;
     */
    @Override // java.lang.Runnable
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public void run() {
        /*
            r4 = this;
            r0 = 0
        L1:
            r1 = r0
        L2:
            g.a.n2.q<java.lang.Runnable> r2 = r4.f4085i
            java.lang.Object r2 = r2.d()
            java.lang.Runnable r2 = (java.lang.Runnable) r2
            if (r2 == 0) goto L2a
            r2.run()     // Catch: java.lang.Throwable -> L10
            goto L16
        L10:
            r2 = move-exception
            f.w.h r3 = f.w.h.f3962b
            g.a.e0.a(r3, r2)
        L16:
            int r1 = r1 + 1
            r2 = 16
            if (r1 < r2) goto L2
            g.a.b0 r2 = r4.f4082f
            boolean r2 = r2.x(r4)
            if (r2 == 0) goto L2
            g.a.b0 r0 = r4.f4082f
            r0.w(r4, r4)
            return
        L2a:
            java.lang.Object r1 = r4.f4086j
            monitor-enter(r1)
            int r2 = r4.runningWorkers     // Catch: java.lang.Throwable -> L47
            int r2 = r2 + (-1)
            r4.runningWorkers = r2     // Catch: java.lang.Throwable -> L47
            g.a.n2.q<java.lang.Runnable> r2 = r4.f4085i     // Catch: java.lang.Throwable -> L47
            int r2 = r2.c()     // Catch: java.lang.Throwable -> L47
            if (r2 != 0) goto L3d
            monitor-exit(r1)
            return
        L3d:
            int r2 = r4.runningWorkers     // Catch: java.lang.Throwable -> L47
            int r2 = r2 + 1
            r4.runningWorkers = r2     // Catch: java.lang.Throwable -> L47
            f.t r2 = f.t.a     // Catch: java.lang.Throwable -> L47
            monitor-exit(r1)
            goto L1
        L47:
            r0 = move-exception
            monitor-exit(r1)
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: g.a.n2.l.run():void");
    }

    @Override // g.a.b0
    public void w(f.w.g gVar, Runnable runnable) {
        if (B(runnable) || !C()) {
            return;
        }
        this.f4082f.w(this, this);
    }

    @Override // g.a.b0
    public g.a.b0 y(int i2) {
        m.a(i2);
        return i2 >= this.f4083g ? this : super.y(i2);
    }
}
