package h;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;

/* JADX INFO: loaded from: classes.dex */
public class c extends y {

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final long f6519e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final long f6520f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    @Nullable
    public static c f6521g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public boolean f6522h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    @Nullable
    public c f6523i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public long f6524j;

    public static final class a extends Thread {
        public a() {
            super("Okio Watchdog");
            setDaemon(true);
        }

        /* JADX WARN: Code restructure failed: missing block: B:14:0x0015, code lost:
        
            r1.m();
         */
        @Override // java.lang.Thread, java.lang.Runnable
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        public void run() {
            /*
                r3 = this;
            L0:
                java.lang.Class<h.c> r0 = h.c.class
                monitor-enter(r0)     // Catch: java.lang.InterruptedException -> L0
                h.c r1 = h.c.h()     // Catch: java.lang.Throwable -> L19
                if (r1 != 0) goto Lb
                monitor-exit(r0)     // Catch: java.lang.Throwable -> L19
                goto L0
            Lb:
                h.c r2 = h.c.f6521g     // Catch: java.lang.Throwable -> L19
                if (r1 != r2) goto L14
                r1 = 0
                h.c.f6521g = r1     // Catch: java.lang.Throwable -> L19
                monitor-exit(r0)     // Catch: java.lang.Throwable -> L19
                return
            L14:
                monitor-exit(r0)     // Catch: java.lang.Throwable -> L19
                r1.m()     // Catch: java.lang.InterruptedException -> L0
                goto L0
            L19:
                r1 = move-exception
                monitor-exit(r0)     // Catch: java.lang.Throwable -> L19
                throw r1     // Catch: java.lang.InterruptedException -> L0
            */
            throw new UnsupportedOperationException("Method not decompiled: h.c.a.run():void");
        }
    }

    static {
        long millis = TimeUnit.SECONDS.toMillis(60L);
        f6519e = millis;
        f6520f = TimeUnit.MILLISECONDS.toNanos(millis);
    }

    @Nullable
    public static c h() throws InterruptedException {
        c cVar = f6521g.f6523i;
        long jNanoTime = System.nanoTime();
        if (cVar == null) {
            c.class.wait(f6519e);
            if (f6521g.f6523i != null || System.nanoTime() - jNanoTime < f6520f) {
                return null;
            }
            return f6521g;
        }
        long j2 = cVar.f6524j - jNanoTime;
        if (j2 > 0) {
            long j3 = j2 / 1000000;
            c.class.wait(j3, (int) (j2 - (1000000 * j3)));
            return null;
        }
        f6521g.f6523i = cVar.f6523i;
        cVar.f6523i = null;
        return cVar;
    }

    /* JADX WARN: Removed duplicated region for block: B:30:0x0065 A[Catch: all -> 0x0070, TRY_LEAVE, TryCatch #0 {, blocks: (B:10:0x0017, B:12:0x001b, B:13:0x002a, B:16:0x0032, B:18:0x003e, B:21:0x004a, B:22:0x004f, B:24:0x0053, B:28:0x005d, B:30:0x0065, B:20:0x0044, B:33:0x006a, B:34:0x006f), top: B:40:0x0017 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final void i() {
        /*
            r9 = this;
            boolean r0 = r9.f6522h
            if (r0 != 0) goto L73
            long r0 = r9.f6574d
            boolean r2 = r9.f6572b
            r3 = 0
            int r3 = (r0 > r3 ? 1 : (r0 == r3 ? 0 : -1))
            if (r3 != 0) goto L11
            if (r2 != 0) goto L11
            return
        L11:
            r4 = 1
            r9.f6522h = r4
            java.lang.Class<h.c> r4 = h.c.class
            monitor-enter(r4)
            h.c r5 = h.c.f6521g     // Catch: java.lang.Throwable -> L70
            if (r5 != 0) goto L2a
            h.c r5 = new h.c     // Catch: java.lang.Throwable -> L70
            r5.<init>()     // Catch: java.lang.Throwable -> L70
            h.c.f6521g = r5     // Catch: java.lang.Throwable -> L70
            h.c$a r5 = new h.c$a     // Catch: java.lang.Throwable -> L70
            r5.<init>()     // Catch: java.lang.Throwable -> L70
            r5.start()     // Catch: java.lang.Throwable -> L70
        L2a:
            long r5 = java.lang.System.nanoTime()     // Catch: java.lang.Throwable -> L70
            if (r3 == 0) goto L3c
            if (r2 == 0) goto L3c
            long r2 = r9.c()     // Catch: java.lang.Throwable -> L70
            long r2 = r2 - r5
            long r0 = java.lang.Math.min(r0, r2)     // Catch: java.lang.Throwable -> L70
            goto L3e
        L3c:
            if (r3 == 0) goto L42
        L3e:
            long r0 = r0 + r5
            r9.f6524j = r0     // Catch: java.lang.Throwable -> L70
            goto L4a
        L42:
            if (r2 == 0) goto L6a
            long r0 = r9.c()     // Catch: java.lang.Throwable -> L70
            r9.f6524j = r0     // Catch: java.lang.Throwable -> L70
        L4a:
            long r0 = r9.f6524j     // Catch: java.lang.Throwable -> L70
            long r0 = r0 - r5
            h.c r2 = h.c.f6521g     // Catch: java.lang.Throwable -> L70
        L4f:
            h.c r3 = r2.f6523i     // Catch: java.lang.Throwable -> L70
            if (r3 == 0) goto L5d
            long r7 = r3.f6524j     // Catch: java.lang.Throwable -> L70
            long r7 = r7 - r5
            int r7 = (r0 > r7 ? 1 : (r0 == r7 ? 0 : -1))
            if (r7 >= 0) goto L5b
            goto L5d
        L5b:
            r2 = r3
            goto L4f
        L5d:
            r9.f6523i = r3     // Catch: java.lang.Throwable -> L70
            r2.f6523i = r9     // Catch: java.lang.Throwable -> L70
            h.c r0 = h.c.f6521g     // Catch: java.lang.Throwable -> L70
            if (r2 != r0) goto L68
            r4.notify()     // Catch: java.lang.Throwable -> L70
        L68:
            monitor-exit(r4)
            return
        L6a:
            java.lang.AssertionError r0 = new java.lang.AssertionError     // Catch: java.lang.Throwable -> L70
            r0.<init>()     // Catch: java.lang.Throwable -> L70
            throw r0     // Catch: java.lang.Throwable -> L70
        L70:
            r0 = move-exception
            monitor-exit(r4)
            throw r0
        L73:
            java.lang.IllegalStateException r0 = new java.lang.IllegalStateException
            java.lang.String r1 = "Unbalanced enter/exit"
            r0.<init>(r1)
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: h.c.i():void");
    }

    public final void j(boolean z) throws IOException {
        if (k() && z) {
            throw l(null);
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:11:0x0013, code lost:
    
        r2.f6523i = r4.f6523i;
        r4.f6523i = null;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final boolean k() {
        /*
            r4 = this;
            boolean r0 = r4.f6522h
            r1 = 0
            if (r0 != 0) goto L6
            return r1
        L6:
            r4.f6522h = r1
            java.lang.Class<h.c> r0 = h.c.class
            monitor-enter(r0)
            h.c r2 = h.c.f6521g     // Catch: java.lang.Throwable -> L20
        Ld:
            if (r2 == 0) goto L1d
            h.c r3 = r2.f6523i     // Catch: java.lang.Throwable -> L20
            if (r3 != r4) goto L1b
            h.c r3 = r4.f6523i     // Catch: java.lang.Throwable -> L20
            r2.f6523i = r3     // Catch: java.lang.Throwable -> L20
            r2 = 0
            r4.f6523i = r2     // Catch: java.lang.Throwable -> L20
            goto L1e
        L1b:
            r2 = r3
            goto Ld
        L1d:
            r1 = 1
        L1e:
            monitor-exit(r0)
            return r1
        L20:
            r1 = move-exception
            monitor-exit(r0)
            throw r1
        */
        throw new UnsupportedOperationException("Method not decompiled: h.c.k():boolean");
    }

    public IOException l(@Nullable IOException iOException) {
        InterruptedIOException interruptedIOException = new InterruptedIOException("timeout");
        if (iOException != null) {
            interruptedIOException.initCause(iOException);
        }
        return interruptedIOException;
    }

    public void m() {
    }
}
