package o; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; /* renamed from: o.fWS, reason: case insensitive filesystem */ /* loaded from: classes6.dex */ public final class C13290fWS extends AbstractC13163fSk { final TimeUnit a; final AbstractC13173fSu b; final fYZ c; RVV d; final long e; private int f; public C13290fWS(fYZ fyz) { this(fyz, TimeUnit.NANOSECONDS); } private C13290fWS(fYZ fyz, TimeUnit timeUnit) { this.c = fyz; this.f = 1; this.e = 0L; this.a = timeUnit; this.b = null; } @Override // o.AbstractC13163fSk public final void subscribeActual(InterfaceC13174fSv interfaceC13174fSv) { RVV rvv; boolean z; synchronized (this) { rvv = this.d; if (rvv == null) { rvv = new RVV(this); this.d = rvv; } long j = rvv.b; if (j == 0 && rvv.d != null) { rvv.d.dispose(); } long j2 = j + 1; rvv.b = j2; if (rvv.c || j2 != this.f) { z = false; } else { z = true; rvv.c = true; } } this.c.subscribe(new IeS(interfaceC13174fSv, this, rvv)); if (z) { this.c.d(rvv); } } final void c(RVV rvv) { synchronized (this) { if (this.d == rvv) { if (rvv.d != null) { rvv.d.dispose(); rvv.d = null; } long j = rvv.b - 1; rvv.b = j; if (j == 0) { this.d = null; this.c.d(); } } } } final void e(RVV rvv) { synchronized (this) { if (rvv.b == 0 && rvv == this.d) { this.d = null; fSJ fsj = rvv.get(); EnumC13192fTf.e(rvv); if (fsj == null) { rvv.e = true; } else { this.c.d(); } } } } /* JADX INFO: Access modifiers changed from: package-private */ /* renamed from: o.fWS$RVV */ /* loaded from: classes6.dex */ public static final class RVV extends AtomicReference implements Runnable, fSQ { private C13290fWS a; long b; boolean c; fSJ d; boolean e; @Override // o.fSQ public final /* synthetic */ void c(fSJ fsj) throws Throwable { EnumC13192fTf.c(this, fsj); synchronized (this.a) { if (this.e) { this.a.c.d(); } } } RVV(C13290fWS c13290fWS) { this.a = c13290fWS; } @Override // java.lang.Runnable public final void run() { this.a.e(this); } } /* renamed from: o.fWS$IeS */ /* loaded from: classes6.dex */ static final class IeS extends AtomicBoolean implements InterfaceC13174fSv, fSJ { private C13290fWS b; private fSJ c; private RVV d; private InterfaceC13174fSv e; IeS(InterfaceC13174fSv interfaceC13174fSv, C13290fWS c13290fWS, RVV rvv) { this.e = interfaceC13174fSv; this.b = c13290fWS; this.d = rvv; } @Override // o.InterfaceC13174fSv public final void onNext(T t) { this.e.onNext(t); } @Override // o.InterfaceC13174fSv public final void onError(Throwable th) { if (compareAndSet(false, true)) { this.b.c(this.d); this.e.onError(th); } else { C13418fZu.c(th); } } @Override // o.InterfaceC13174fSv public final void onComplete() { if (compareAndSet(false, true)) { this.b.c(this.d); this.e.onComplete(); } } @Override // o.fSJ public final void dispose() { this.c.dispose(); if (compareAndSet(false, true)) { C13290fWS c13290fWS = this.b; RVV rvv = this.d; synchronized (c13290fWS) { RVV rvv2 = c13290fWS.d; if (rvv2 == null || rvv2 != rvv) { return; } long j = rvv.b - 1; rvv.b = j; if (j == 0 && rvv.c) { if (c13290fWS.e == 0) { c13290fWS.e(rvv); return; } rvv.d = new C13197fTk(); AbstractC13173fSu abstractC13173fSu = c13290fWS.b; long j2 = c13290fWS.e; TimeUnit timeUnit = c13290fWS.a; throw null; } } } } @Override // o.fSJ public final boolean isDisposed() { return this.c.isDisposed(); } @Override // o.InterfaceC13174fSv public final void onSubscribe(fSJ fsj) { if (EnumC13192fTf.d(this.c, fsj)) { this.c = fsj; this.e.onSubscribe(this); } } } }