package com.facetec.sdk; import java.io.IOException; import java.io.InterruptedIOException; import java.util.concurrent.TimeUnit; /* loaded from: classes.dex */ public class mo extends nh { static mo a; private static final long b; private static final long e; private boolean d; private long g; private mo j; protected void d() { } static { long millis = TimeUnit.SECONDS.toMillis(60L); b = millis; e = TimeUnit.MILLISECONDS.toNanos(millis); } public final void e() { if (this.d) { throw new IllegalStateException("Unbalanced enter/exit"); } long a_ = a_(); boolean b_ = b_(); if (a_ != 0 || b_) { this.d = true; c(this, a_, b_); } } private static void c(mo moVar, long j, boolean z) { synchronized (mo.class) { if (a == null) { a = new mo(); new a().start(); } long nanoTime = System.nanoTime(); if (j != 0 && z) { moVar.g = Math.min(j, moVar.c_() - nanoTime) + nanoTime; } else if (j != 0) { moVar.g = j + nanoTime; } else if (z) { moVar.g = moVar.c_(); } else { throw new AssertionError(); } long a2 = moVar.a(nanoTime); mo moVar2 = a; while (true) { mo moVar3 = moVar2.j; if (moVar3 == null || a2 < moVar3.a(nanoTime)) { break; } else { moVar2 = moVar2.j; } } moVar.j = moVar2.j; moVar2.j = moVar; if (moVar2 == a) { mo.class.notify(); } } } public final boolean a() { if (!this.d) { return false; } this.d = false; return b(this); } private static boolean b(mo moVar) { synchronized (mo.class) { mo moVar2 = a; while (moVar2 != null) { mo moVar3 = moVar2.j; if (moVar3 == moVar) { moVar2.j = moVar.j; moVar.j = null; return false; } moVar2 = moVar3; } return true; } } final void d(boolean z) throws IOException { if (a() && z) { throw a((IOException) null); } } final IOException d(IOException iOException) throws IOException { return !a() ? iOException : a(iOException); } protected IOException a(IOException iOException) { InterruptedIOException interruptedIOException = new InterruptedIOException("timeout"); if (iOException != null) { interruptedIOException.initCause(iOException); } return interruptedIOException; } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public static final class a extends Thread { a() { super("Okio Watchdog"); setDaemon(true); } /* JADX WARN: Code restructure failed: missing block: B:19:0x0015, code lost: r1.d(); */ @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 final void run() { /* r3 = this; L0: java.lang.Class r0 = com.facetec.sdk.mo.class monitor-enter(r0) // Catch: java.lang.InterruptedException -> L0 com.facetec.sdk.mo r1 = com.facetec.sdk.mo.b() // Catch: java.lang.Throwable -> L19 if (r1 != 0) goto Lb monitor-exit(r0) goto L0 Lb: com.facetec.sdk.mo r2 = com.facetec.sdk.mo.a // Catch: java.lang.Throwable -> L19 if (r1 != r2) goto L14 r1 = 0 com.facetec.sdk.mo.a = r1 // Catch: java.lang.Throwable -> L19 monitor-exit(r0) return L14: monitor-exit(r0) r1.d() // Catch: java.lang.InterruptedException -> L0 goto L0 L19: r1 = move-exception monitor-exit(r0) // Catch: java.lang.InterruptedException -> L0 throw r1 // Catch: java.lang.InterruptedException -> L0 */ throw new UnsupportedOperationException("Method not decompiled: com.facetec.sdk.mo.a.run():void"); } } static mo b() throws InterruptedException { mo moVar = a.j; if (moVar == null) { long nanoTime = System.nanoTime(); mo.class.wait(b); if (a.j != null || System.nanoTime() - nanoTime < e) { return null; } return a; } long a2 = moVar.a(System.nanoTime()); if (a2 > 0) { long j = a2 / 1000000; mo.class.wait(j, (int) (a2 - (1000000 * j))); return null; } a.j = moVar.j; moVar.j = null; return moVar; } private long a(long j) { return this.g - j; } }