package o; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; /* renamed from: o.fUS, reason: case insensitive filesystem */ /* loaded from: classes6.dex */ public final class C13219fUS extends AbstractC13163fSk { private AbstractC13163fSk a; private fSS> c; private boolean d; public C13219fUS(AbstractC13163fSk abstractC13163fSk, fSS> fss, boolean z) { this.a = abstractC13163fSk; this.c = fss; this.d = z; } @Override // o.AbstractC13163fSk public final void subscribeActual(InterfaceC13174fSv interfaceC13174fSv) { if (fUP.e(this.a, this.c, interfaceC13174fSv)) { return; } this.a.subscribe(new HBt(interfaceC13174fSv, this.c, this.d)); } /* renamed from: o.fUS$HBt */ /* loaded from: classes6.dex */ static final class HBt extends AtomicInteger implements InterfaceC13174fSv, fSJ { private static IeS b = new IeS<>(null); final boolean a; final C13355fYI c = new C13355fYI(); final AtomicReference> d = new AtomicReference<>(); fSJ e; private volatile boolean g; private InterfaceC13174fSv h; private fSS> i; private volatile boolean j; HBt(InterfaceC13174fSv interfaceC13174fSv, fSS> fss, boolean z) { this.h = interfaceC13174fSv; this.i = fss; this.a = z; } @Override // o.InterfaceC13174fSv public final void onSubscribe(fSJ fsj) { if (EnumC13192fTf.d(this.e, fsj)) { this.e = fsj; this.h.onSubscribe(this); } } @Override // o.InterfaceC13174fSv public final void onNext(T t) { IeS ieS = this.d.get(); if (ieS != null) { EnumC13192fTf.e(ieS); } try { InterfaceC13160fSh interfaceC13160fSh = (InterfaceC13160fSh) Objects.requireNonNull(this.i.a(t), "The mapper returned a null MaybeSource"); IeS ieS2 = new IeS<>(this); while (true) { IeS ieS3 = this.d.get(); if (ieS3 != b) { AtomicReference> atomicReference = this.d; while (!atomicReference.compareAndSet(ieS3, ieS2)) { if (atomicReference.get() != ieS3) { break; } } interfaceC13160fSh.c(ieS2); return; } return; } } catch (Throwable th) { C13147fSI.c(th); this.e.dispose(); this.d.getAndSet(b); onError(th); } } @Override // o.InterfaceC13174fSv public final void onComplete() { this.g = true; b(); } final void a() { AtomicReference> atomicReference = this.d; IeS ieS = b; IeS ieS2 = (IeS) atomicReference.getAndSet(ieS); if (ieS2 == null || ieS2 == ieS) { return; } EnumC13192fTf.e(ieS2); } @Override // o.fSJ public final void dispose() { this.j = true; this.e.dispose(); AtomicReference> atomicReference = this.d; IeS ieS = b; IeS ieS2 = (IeS) atomicReference.getAndSet(ieS); if (ieS2 != null && ieS2 != ieS) { EnumC13192fTf.e(ieS2); } Throwable b2 = fYR.b(this.c); if (b2 == null || b2 == fYR.b) { return; } C13418fZu.c(b2); } final void b() { if (getAndIncrement() != 0) { return; } InterfaceC13174fSv interfaceC13174fSv = this.h; C13355fYI c13355fYI = this.c; AtomicReference> atomicReference = this.d; int i = 1; while (!this.j) { if (c13355fYI.get() == null || this.a) { boolean z = this.g; IeS ieS = atomicReference.get(); boolean z2 = ieS == null; if (!z || !z2) { if (z2 || ieS.b == null) { i = addAndGet(-i); if (i == 0) { return; } } else { while (!atomicReference.compareAndSet(ieS, null) && atomicReference.get() == ieS) { } interfaceC13174fSv.onNext(ieS.b); } } else { Throwable b2 = fYR.b(c13355fYI); if (b2 == null) { interfaceC13174fSv.onComplete(); return; } else { if (b2 != fYR.b) { interfaceC13174fSv.onError(b2); return; } return; } } } else { Throwable b3 = fYR.b(c13355fYI); if (b3 == null) { interfaceC13174fSv.onComplete(); return; } else { if (b3 != fYR.b) { interfaceC13174fSv.onError(b3); return; } return; } } } } /* JADX INFO: Access modifiers changed from: package-private */ /* renamed from: o.fUS$HBt$IeS */ /* loaded from: classes6.dex */ public static final class IeS extends AtomicReference implements InterfaceC13161fSi { private HBt a; volatile R b; IeS(HBt hBt) { this.a = hBt; } @Override // o.InterfaceC13161fSi public final void onSubscribe(fSJ fsj) { EnumC13192fTf.a(this, fsj); } @Override // o.InterfaceC13161fSi public final void e(R r) { this.b = r; this.a.b(); } @Override // o.InterfaceC13161fSi public final void onError(Throwable th) { HBt hBt = this.a; AtomicReference> atomicReference = hBt.d; while (!atomicReference.compareAndSet(this, null)) { if (atomicReference.get() != this) { C13418fZu.c(th); return; } } if (fYR.c(hBt.c, th)) { if (!hBt.a) { hBt.e.dispose(); hBt.a(); } hBt.b(); return; } C13418fZu.c(th); } @Override // o.InterfaceC13161fSi public final void onComplete() { HBt hBt = this.a; AtomicReference> atomicReference = hBt.d; while (!atomicReference.compareAndSet(this, null)) { if (atomicReference.get() != this) { return; } } hBt.b(); } } @Override // o.InterfaceC13174fSv public final void onError(Throwable th) { if (fYR.c(this.c, th)) { if (!this.a) { a(); } this.g = true; b(); return; } C13418fZu.c(th); } @Override // o.fSJ public final boolean isDisposed() { return this.j; } } }