package o; import java.util.Collection; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; /* renamed from: o.fVg, reason: case insensitive filesystem */ /* loaded from: classes6.dex */ public final class C13263fVg, Open, Close> extends fUX { private InterfaceC13169fSq a; private InterfaceC13189fTc d; private fSS> e; public C13263fVg(InterfaceC13169fSq interfaceC13169fSq, InterfaceC13169fSq interfaceC13169fSq2, fSS> fss, InterfaceC13189fTc interfaceC13189fTc) { super(interfaceC13169fSq); this.a = interfaceC13169fSq2; this.e = fss; this.d = interfaceC13189fTc; } @Override // o.AbstractC13163fSk public final void subscribeActual(InterfaceC13174fSv interfaceC13174fSv) { RVV rvv = new RVV(interfaceC13174fSv, this.a, this.e, this.d); interfaceC13174fSv.onSubscribe(rvv); this.c.subscribe(rvv); } /* renamed from: o.fVg$RVV */ /* loaded from: classes6.dex */ static final class RVV, Open, Close> extends AtomicInteger implements InterfaceC13174fSv, fSJ { long a; final fSS> b; volatile boolean c; final InterfaceC13189fTc e; private volatile boolean g; private InterfaceC13174fSv h; private InterfaceC13169fSq i; private C13416fZs l = new C13416fZs<>(AbstractC13163fSk.bufferSize()); final fSC f = new fSC(); final AtomicReference j = new AtomicReference<>(); Map d = new LinkedHashMap(); private C13355fYI n = new C13355fYI(); RVV(InterfaceC13174fSv interfaceC13174fSv, InterfaceC13169fSq interfaceC13169fSq, fSS> fss, InterfaceC13189fTc interfaceC13189fTc) { this.h = interfaceC13174fSv; this.e = interfaceC13189fTc; this.i = interfaceC13169fSq; this.b = fss; } @Override // o.InterfaceC13174fSv public final void onSubscribe(fSJ fsj) { if (EnumC13192fTf.a(this.j, fsj)) { HBt hBt = new HBt(this); this.f.e(hBt); this.i.subscribe(hBt); } } @Override // o.InterfaceC13174fSv public final void onNext(T t) { synchronized (this) { Map map = this.d; if (map == null) { return; } Iterator it = map.values().iterator(); while (it.hasNext()) { it.next().add(t); } } } @Override // o.InterfaceC13174fSv public final void onComplete() { this.f.dispose(); synchronized (this) { Map map = this.d; if (map == null) { return; } Iterator it = map.values().iterator(); while (it.hasNext()) { this.l.b(it.next()); } this.d = null; this.c = true; e(); } } @Override // o.fSJ public final void dispose() { if (EnumC13192fTf.e(this.j)) { this.g = true; this.f.dispose(); synchronized (this) { this.d = null; } if (getAndIncrement() != 0) { this.l.e(); } } } @Override // o.fSJ public final boolean isDisposed() { return EnumC13192fTf.c(this.j.get()); } final void a(HBt hBt, long j) { boolean z; this.f.b(hBt); if (this.f.e() == 0) { EnumC13192fTf.e(this.j); z = true; } else { z = false; } synchronized (this) { Map map = this.d; if (map == null) { return; } this.l.b(map.remove(Long.valueOf(j))); if (z) { this.c = true; } e(); } } final void e() { if (getAndIncrement() != 0) { return; } InterfaceC13174fSv interfaceC13174fSv = this.h; C13416fZs c13416fZs = this.l; int i = 1; while (!this.g) { boolean z = this.c; if (z && this.n.get() != null) { c13416fZs.e(); Throwable b = fYR.b(this.n); if (b == null) { interfaceC13174fSv.onComplete(); return; } else { if (b != fYR.b) { interfaceC13174fSv.onError(b); return; } return; } } C b2 = c13416fZs.b(); boolean z2 = b2 == null; if (z && z2) { interfaceC13174fSv.onComplete(); return; } else if (!z2) { interfaceC13174fSv.onNext(b2); } else { i = addAndGet(-i); if (i == 0) { return; } } } c13416fZs.e(); } /* renamed from: o.fVg$RVV$HBt */ /* loaded from: classes6.dex */ static final class HBt extends AtomicReference implements InterfaceC13174fSv, fSJ { private RVV e; HBt(RVV rvv) { this.e = rvv; } @Override // o.InterfaceC13174fSv public final void onSubscribe(fSJ fsj) { EnumC13192fTf.a(this, fsj); } @Override // o.InterfaceC13174fSv public final void onNext(Open open) { RVV rvv = this.e; try { Collection collection = (Collection) Objects.requireNonNull(rvv.e.d(), "The bufferSupplier returned a null Collection"); InterfaceC13169fSq interfaceC13169fSq = (InterfaceC13169fSq) Objects.requireNonNull(rvv.b.a(open), "The bufferClose returned a null ObservableSource"); long j = rvv.a; rvv.a = 1 + j; synchronized (rvv) { Map map = rvv.d; if (map == null) { return; } map.put(Long.valueOf(j), collection); HBt hBt = new HBt(rvv, j); rvv.f.e(hBt); interfaceC13169fSq.subscribe(hBt); } } catch (Throwable th) { C13147fSI.c(th); EnumC13192fTf.e(rvv.j); rvv.onError(th); } } @Override // o.InterfaceC13174fSv public final void onError(Throwable th) { lazySet(EnumC13192fTf.DISPOSED); RVV rvv = this.e; EnumC13192fTf.e(rvv.j); rvv.f.b(this); rvv.onError(th); } @Override // o.InterfaceC13174fSv public final void onComplete() { lazySet(EnumC13192fTf.DISPOSED); RVV rvv = this.e; rvv.f.b(this); if (rvv.f.e() == 0) { EnumC13192fTf.e(rvv.j); rvv.c = true; rvv.e(); } } @Override // o.fSJ public final void dispose() { EnumC13192fTf.e(this); } @Override // o.fSJ public final boolean isDisposed() { return get() == EnumC13192fTf.DISPOSED; } } @Override // o.InterfaceC13174fSv public final void onError(Throwable th) { if (fYR.c(this.n, th)) { this.f.dispose(); synchronized (this) { this.d = null; } this.c = true; e(); return; } C13418fZu.c(th); } } /* renamed from: o.fVg$HBt */ /* loaded from: classes6.dex */ static final class HBt> extends AtomicReference implements InterfaceC13174fSv, fSJ { private RVV b; private long e; HBt(RVV rvv, long j) { this.b = rvv; this.e = j; } @Override // o.InterfaceC13174fSv public final void onSubscribe(fSJ fsj) { EnumC13192fTf.a(this, fsj); } @Override // o.InterfaceC13174fSv public final void onNext(Object obj) { fSJ fsj = get(); if (fsj != EnumC13192fTf.DISPOSED) { lazySet(EnumC13192fTf.DISPOSED); fsj.dispose(); this.b.a(this, this.e); } } @Override // o.InterfaceC13174fSv public final void onError(Throwable th) { if (get() != EnumC13192fTf.DISPOSED) { lazySet(EnumC13192fTf.DISPOSED); RVV rvv = this.b; EnumC13192fTf.e(rvv.j); rvv.f.b(this); rvv.onError(th); return; } C13418fZu.c(th); } @Override // o.InterfaceC13174fSv public final void onComplete() { if (get() != EnumC13192fTf.DISPOSED) { lazySet(EnumC13192fTf.DISPOSED); this.b.a(this, this.e); } } @Override // o.fSJ public final void dispose() { EnumC13192fTf.e(this); } @Override // o.fSJ public final boolean isDisposed() { return get() == EnumC13192fTf.DISPOSED; } } }