package ᨨ;

import java.io.IOException;
import java.io.InterruptedIOException;
import java.util.concurrent.TimeUnit;

/* renamed from: ᨨ.ʬ  reason: contains not printable characters */
/* compiled from: AsyncTimeout */
public class C1470 extends C1477 {

    /* renamed from: ᨨ  reason: contains not printable characters */
    public static final long f5485 = TimeUnit.MILLISECONDS.toNanos(f5487);

    /* renamed from: 㳳  reason: contains not printable characters */
    public static C1470 f5486;

    /* renamed from: 㿎  reason: contains not printable characters */
    public static final long f5487 = TimeUnit.SECONDS.toMillis(60);

    /* renamed from: ඓ  reason: contains not printable characters */
    public boolean f5488;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public long f5489;

    /* renamed from: 㴹  reason: contains not printable characters */
    public C1470 f5490;

    /* renamed from: ᨨ.ʬ$K  reason: contains not printable characters */
    /* compiled from: AsyncTimeout */
    public static final class C1471 extends Thread {
        public C1471() {
            super("Okio Watchdog");
            setDaemon(true);
        }

        /* JADX WARNING: Code restructure failed: missing block: B:15:0x0015, code lost:
            r1.m3690();
         */
        public void run() {
            while (true) {
                try {
                    synchronized (C1470.class) {
                        C1470 r1 = C1470.m3683();
                        if (r1 != null) {
                            if (r1 == C1470.f5486) {
                                C1470.f5486 = null;
                                return;
                            }
                        }
                    }
                } catch (InterruptedException unused) {
                }
            }
        }
    }

    /* renamed from: ᨨ  reason: contains not printable characters */
    public static C1470 m3683() throws InterruptedException {
        C1470 r1 = f5486.f5490;
        if (r1 == null) {
            long nanoTime = System.nanoTime();
            C1470.class.wait(f5487);
            if (f5486.f5490 != null || System.nanoTime() - nanoTime < f5485) {
                return null;
            }
            return f5486;
        }
        long nanoTime2 = r1.f5489 - System.nanoTime();
        if (nanoTime2 > 0) {
            long j = nanoTime2 / 1000000;
            C1470.class.wait(j, (int) (nanoTime2 - (1000000 * j)));
            return null;
        }
        f5486.f5490 = r1.f5490;
        r1.f5490 = null;
        return r1;
    }

    /* renamed from: K  reason: contains not printable characters */
    public static synchronized void m3684(C1470 r7, long j, boolean z) {
        synchronized (C1470.class) {
            if (f5486 == null) {
                f5486 = new C1470();
                new C1471().start();
            }
            long nanoTime = System.nanoTime();
            int i = (j > 0 ? 1 : (j == 0 ? 0 : -1));
            if (i != 0 && z) {
                r7.f5489 = Math.min(j, r7.m3700() - nanoTime) + nanoTime;
            } else if (i != 0) {
                r7.f5489 = j + nanoTime;
            } else if (z) {
                r7.f5489 = r7.m3700();
            } else {
                throw new AssertionError();
            }
            long j2 = r7.f5489 - nanoTime;
            C1470 r10 = f5486;
            while (true) {
                if (r10.f5490 == null) {
                    break;
                }
                C1470 r3 = r10.f5490;
                if (j2 < r3.f5489 - nanoTime) {
                    break;
                }
                r10 = r3;
            }
            r7.f5490 = r10.f5490;
            r10.f5490 = r7;
            if (r10 == f5486) {
                C1470.class.notify();
            }
        }
    }

    /* renamed from: ⁱ  reason: contains not printable characters */
    public final boolean m3686() {
        if (!this.f5488) {
            return false;
        }
        this.f5488 = false;
        return m3685(this);
    }

    /* renamed from: 㴹  reason: contains not printable characters */
    public final void m3689() {
        if (!this.f5488) {
            long j = this.f5503;
            boolean z = this.f5505;
            if (j != 0 || z) {
                this.f5488 = true;
                m3684(this, j, z);
                return;
            }
            return;
        }
        throw new IllegalStateException("Unbalanced enter/exit");
    }

    /* renamed from: 㿎  reason: contains not printable characters */
    public void m3690() {
    }

    /* renamed from: K  reason: contains not printable characters */
    public static synchronized boolean m3685(C1470 r3) {
        synchronized (C1470.class) {
            C1470 r1 = f5486;
            while (r1 != null) {
                C1470 r2 = r1.f5490;
                if (r2 == r3) {
                    r1.f5490 = r3.f5490;
                    r3.f5490 = null;
                    return false;
                }
                r1 = r2;
            }
            return true;
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public final void m3688(boolean z) throws IOException {
        if (m3686() && z) {
            throw m3687((IOException) null);
        }
    }

    /* renamed from: K  reason: contains not printable characters */
    public IOException m3687(IOException iOException) {
        InterruptedIOException interruptedIOException = new InterruptedIOException("timeout");
        if (iOException != null) {
            interruptedIOException.initCause(iOException);
        }
        return interruptedIOException;
    }
}
