package h.a.k1;

import h.a.x;

/* JADX INFO: compiled from: LimitedDispatcher.kt */
/* JADX INFO: loaded from: classes.dex */
@g.i
public final class f extends h.a.q implements Runnable, x {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final h.a.q f4249e;

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final /* synthetic */ x f4251g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final j<Runnable> f4252h;

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

    /* JADX WARN: Multi-variable type inference failed */
    public f(h.a.q qVar, int i2) {
        this.f4249e = qVar;
        this.f4250f = i2;
        x xVar = qVar instanceof x ? (x) qVar : null;
        this.f4251g = xVar == null ? h.a.w.f4340b : xVar;
        this.f4252h = new j<>(false);
        this.f4253i = new Object();
    }

    @Override // h.a.q
    public void e(g.e0.f fVar, Runnable runnable) {
        this.f4252h.a(runnable);
        if (!(this.runningWorkers >= this.f4250f) && t()) {
            this.f4249e.e(this, this);
        }
    }

    @Override // h.a.q
    public void f(g.e0.f fVar, Runnable runnable) {
        this.f4252h.a(runnable);
        if (!(this.runningWorkers >= this.f4250f) && t()) {
            this.f4249e.f(this, this);
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:16:0x002a, code lost:
    
        r1 = r4.f4253i;
     */
    /* 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.f4252h.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++;
     */
    @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:
            h.a.k1.j<java.lang.Runnable> r2 = r4.f4252h
            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
            g.e0.h r3 = g.e0.h.f4083b
            f.a.y.a.j0(r3, r2)
        L16:
            int r1 = r1 + 1
            r2 = 16
            if (r1 < r2) goto L2
            h.a.q r2 = r4.f4249e
            boolean r2 = r2.q(r4)
            if (r2 == 0) goto L2
            h.a.q r0 = r4.f4249e
            r0.e(r4, r4)
            return
        L2a:
            java.lang.Object r1 = r4.f4253i
            monitor-enter(r1)
            int r2 = r4.runningWorkers     // Catch: java.lang.Throwable -> L45
            int r2 = r2 + (-1)
            r4.runningWorkers = r2     // Catch: java.lang.Throwable -> L45
            h.a.k1.j<java.lang.Runnable> r2 = r4.f4252h     // Catch: java.lang.Throwable -> L45
            int r2 = r2.c()     // Catch: java.lang.Throwable -> L45
            if (r2 != 0) goto L3d
            monitor-exit(r1)
            return
        L3d:
            int r2 = r4.runningWorkers     // Catch: java.lang.Throwable -> L45
            int r2 = r2 + 1
            r4.runningWorkers = r2     // Catch: java.lang.Throwable -> L45
            monitor-exit(r1)
            goto L1
        L45:
            r0 = move-exception
            monitor-exit(r1)
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: h.a.k1.f.run():void");
    }

    public final boolean t() {
        synchronized (this.f4253i) {
            if (this.runningWorkers >= this.f4250f) {
                return false;
            }
            this.runningWorkers++;
            return true;
        }
    }
}
