283 lines
8.5 KiB
Java
283 lines
8.5 KiB
Java
|
package o;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.io.InterruptedIOException;
|
||
|
|
||
|
/* renamed from: o.giG, reason: case insensitive filesystem */
|
||
|
/* loaded from: classes6.dex */
|
||
|
public class C15140giG extends giY {
|
||
|
private static C15140giG amZ;
|
||
|
private boolean ana;
|
||
|
private C15140giG anb;
|
||
|
private long anc;
|
||
|
|
||
|
protected void timedOut() {
|
||
|
}
|
||
|
|
||
|
static /* synthetic */ C15140giG vv() throws InterruptedException {
|
||
|
return vu();
|
||
|
}
|
||
|
|
||
|
public final void enter() {
|
||
|
if (this.ana) {
|
||
|
throw new IllegalStateException("Unbalanced enter/exit");
|
||
|
}
|
||
|
long timeoutNanos = timeoutNanos();
|
||
|
boolean hasDeadline = hasDeadline();
|
||
|
if (timeoutNanos != 0 || hasDeadline) {
|
||
|
this.ana = true;
|
||
|
a(this, timeoutNanos, hasDeadline);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static void a(C15140giG c15140giG, long j, boolean z) {
|
||
|
synchronized (C15140giG.class) {
|
||
|
if (amZ == null) {
|
||
|
amZ = new C15140giG();
|
||
|
new LWm().start();
|
||
|
}
|
||
|
long nanoTime = System.nanoTime();
|
||
|
if (j != 0 && z) {
|
||
|
c15140giG.anc = Math.min(j, c15140giG.deadlineNanoTime() - nanoTime) + nanoTime;
|
||
|
} else if (j != 0) {
|
||
|
c15140giG.anc = j + nanoTime;
|
||
|
} else if (z) {
|
||
|
c15140giG.anc = c15140giG.deadlineNanoTime();
|
||
|
} else {
|
||
|
throw new AssertionError();
|
||
|
}
|
||
|
long f = c15140giG.f(nanoTime);
|
||
|
C15140giG c15140giG2 = amZ;
|
||
|
while (true) {
|
||
|
C15140giG c15140giG3 = c15140giG2.anb;
|
||
|
if (c15140giG3 == null || f < c15140giG3.f(nanoTime)) {
|
||
|
break;
|
||
|
} else {
|
||
|
c15140giG2 = c15140giG2.anb;
|
||
|
}
|
||
|
}
|
||
|
c15140giG.anb = c15140giG2.anb;
|
||
|
c15140giG2.anb = c15140giG;
|
||
|
if (c15140giG2 == amZ) {
|
||
|
C15140giG.class.notify();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final boolean exit() {
|
||
|
if (!this.ana) {
|
||
|
return false;
|
||
|
}
|
||
|
this.ana = false;
|
||
|
return a(this);
|
||
|
}
|
||
|
|
||
|
private static boolean a(C15140giG c15140giG) {
|
||
|
synchronized (C15140giG.class) {
|
||
|
C15140giG c15140giG2 = amZ;
|
||
|
while (c15140giG2 != null) {
|
||
|
C15140giG c15140giG3 = c15140giG2.anb;
|
||
|
if (c15140giG3 == c15140giG) {
|
||
|
c15140giG2.anb = c15140giG.anb;
|
||
|
c15140giG.anb = null;
|
||
|
return false;
|
||
|
}
|
||
|
c15140giG2 = c15140giG3;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final giX sink(giX gix) {
|
||
|
return new giX(this, gix) { // from class: o.giG.5
|
||
|
private giX a;
|
||
|
private C15140giG b;
|
||
|
|
||
|
{
|
||
|
this.b = this;
|
||
|
this.a = gix;
|
||
|
}
|
||
|
|
||
|
@Override // o.giX
|
||
|
public final void write(giM gim, long j) throws IOException {
|
||
|
this.b.enter();
|
||
|
try {
|
||
|
try {
|
||
|
this.a.write(gim, j);
|
||
|
this.b.exit(true);
|
||
|
} catch (IOException e) {
|
||
|
throw this.b.exit(e);
|
||
|
}
|
||
|
} catch (Throwable th) {
|
||
|
this.b.exit(false);
|
||
|
throw th;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // o.giX, java.io.Flushable
|
||
|
public final void flush() throws IOException {
|
||
|
this.b.enter();
|
||
|
try {
|
||
|
try {
|
||
|
this.a.flush();
|
||
|
this.b.exit(true);
|
||
|
} catch (IOException e) {
|
||
|
throw this.b.exit(e);
|
||
|
}
|
||
|
} catch (Throwable th) {
|
||
|
this.b.exit(false);
|
||
|
throw th;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // o.giX, java.io.Closeable, java.lang.AutoCloseable
|
||
|
public final void close() throws IOException {
|
||
|
this.b.enter();
|
||
|
try {
|
||
|
try {
|
||
|
this.a.close();
|
||
|
this.b.exit(true);
|
||
|
} catch (IOException e) {
|
||
|
throw this.b.exit(e);
|
||
|
}
|
||
|
} catch (Throwable th) {
|
||
|
this.b.exit(false);
|
||
|
throw th;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final String toString() {
|
||
|
StringBuilder sb = new StringBuilder("AsyncTimeout.sink(");
|
||
|
sb.append(this.a);
|
||
|
sb.append(")");
|
||
|
return sb.toString();
|
||
|
}
|
||
|
|
||
|
@Override // o.giX
|
||
|
public final giY timeout() {
|
||
|
return this.b;
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
public final giZ source(giZ giz) {
|
||
|
return new giZ(this, giz) { // from class: o.giG.4
|
||
|
private C15140giG a;
|
||
|
private giZ c;
|
||
|
|
||
|
{
|
||
|
this.a = this;
|
||
|
this.c = giz;
|
||
|
}
|
||
|
|
||
|
@Override // o.giZ
|
||
|
public final long read(giM gim, long j) throws IOException {
|
||
|
this.a.enter();
|
||
|
try {
|
||
|
try {
|
||
|
long read = this.c.read(gim, j);
|
||
|
this.a.exit(true);
|
||
|
return read;
|
||
|
} catch (IOException e) {
|
||
|
throw this.a.exit(e);
|
||
|
}
|
||
|
} catch (Throwable th) {
|
||
|
this.a.exit(false);
|
||
|
throw th;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override // o.giZ, java.io.Closeable, java.lang.AutoCloseable
|
||
|
public final void close() throws IOException {
|
||
|
try {
|
||
|
try {
|
||
|
this.c.close();
|
||
|
this.a.exit(true);
|
||
|
} catch (IOException e) {
|
||
|
throw this.a.exit(e);
|
||
|
}
|
||
|
} catch (Throwable th) {
|
||
|
this.a.exit(false);
|
||
|
throw th;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public final String toString() {
|
||
|
StringBuilder sb = new StringBuilder("AsyncTimeout.source(");
|
||
|
sb.append(this.c);
|
||
|
sb.append(")");
|
||
|
return sb.toString();
|
||
|
}
|
||
|
|
||
|
@Override // o.giZ
|
||
|
public final giY timeout() {
|
||
|
return this.a;
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
|
||
|
final void exit(boolean z) throws IOException {
|
||
|
if (exit() && z) {
|
||
|
throw newTimeoutException(null);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
final IOException exit(IOException iOException) throws IOException {
|
||
|
return !exit() ? iOException : newTimeoutException(iOException);
|
||
|
}
|
||
|
|
||
|
protected IOException newTimeoutException(IOException iOException) {
|
||
|
InterruptedIOException interruptedIOException = new InterruptedIOException("timeout");
|
||
|
if (iOException != null) {
|
||
|
interruptedIOException.initCause(iOException);
|
||
|
}
|
||
|
return interruptedIOException;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: package-private */
|
||
|
/* renamed from: o.giG$LWm */
|
||
|
/* loaded from: classes6.dex */
|
||
|
public static final class LWm extends Thread {
|
||
|
public LWm() {
|
||
|
super("Okio Watchdog");
|
||
|
setDaemon(true);
|
||
|
}
|
||
|
|
||
|
@Override // java.lang.Thread, java.lang.Runnable
|
||
|
public final void run() {
|
||
|
while (true) {
|
||
|
try {
|
||
|
C15140giG vv = C15140giG.vv();
|
||
|
if (vv != null) {
|
||
|
vv.timedOut();
|
||
|
}
|
||
|
} catch (InterruptedException unused) {
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private static C15140giG vu() throws InterruptedException {
|
||
|
synchronized (C15140giG.class) {
|
||
|
C15140giG c15140giG = amZ.anb;
|
||
|
if (c15140giG == null) {
|
||
|
C15140giG.class.wait();
|
||
|
return null;
|
||
|
}
|
||
|
long f = c15140giG.f(System.nanoTime());
|
||
|
if (f > 0) {
|
||
|
long j = f / 1000000;
|
||
|
C15140giG.class.wait(j, (int) (f - (1000000 * j)));
|
||
|
return null;
|
||
|
}
|
||
|
amZ.anb = c15140giG.anb;
|
||
|
c15140giG.anb = null;
|
||
|
return c15140giG;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private long f(long j) {
|
||
|
return this.anc - j;
|
||
|
}
|
||
|
}
|