package o; import java.util.ArrayList; import java.util.Objects; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; /* loaded from: classes6.dex */ public final class fWZ extends fYZ { private static HBt d = new jNh(); private AtomicReference> a; private InterfaceC13169fSq b; private InterfaceC13169fSq c; private HBt e; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public interface HBt { jbe d(); } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public interface jbe { void b(Throwable th); void b(Sts sts); void c(T t); void d(); } public static AbstractC13163fSk a(InterfaceC13189fTc> interfaceC13189fTc, fSS, ? extends InterfaceC13169fSq> fss) { return new IeS(interfaceC13189fTc, fss); } public static fYZ b(InterfaceC13169fSq interfaceC13169fSq, int i, boolean z) { if (i == Integer.MAX_VALUE) { HBt hBt = d; AtomicReference atomicReference = new AtomicReference(); return new fWZ(new saX(atomicReference, hBt), interfaceC13169fSq, atomicReference, hBt); } ZqN zqN = new ZqN(i, z); AtomicReference atomicReference2 = new AtomicReference(); return new fWZ(new saX(atomicReference2, zqN), interfaceC13169fSq, atomicReference2, zqN); } public static fYZ b(InterfaceC13169fSq interfaceC13169fSq, long j, TimeUnit timeUnit, AbstractC13173fSu abstractC13173fSu, int i, boolean z) { vUG vug = new vUG(i, j, timeUnit, abstractC13173fSu, z); AtomicReference atomicReference = new AtomicReference(); return new fWZ(new saX(atomicReference, vug), interfaceC13169fSq, atomicReference, vug); } private fWZ(InterfaceC13169fSq interfaceC13169fSq, InterfaceC13169fSq interfaceC13169fSq2, AtomicReference> atomicReference, HBt hBt) { this.c = interfaceC13169fSq; this.b = interfaceC13169fSq2; this.a = atomicReference; this.e = hBt; } @Override // o.fYZ public final void d() { tOB tob = this.a.get(); if (tob == null || !tob.isDisposed()) { return; } AtomicReference> atomicReference = this.a; while (!atomicReference.compareAndSet(tob, null) && atomicReference.get() == tob) { } } @Override // o.AbstractC13163fSk public final void subscribeActual(InterfaceC13174fSv interfaceC13174fSv) { this.c.subscribe(interfaceC13174fSv); } @Override // o.fYZ public final void d(fSQ fsq) { tOB tob; loop0: while (true) { tob = this.a.get(); if (tob != null && !tob.isDisposed()) { break; } tOB tob2 = new tOB<>(this.e.d(), this.a); AtomicReference> atomicReference = this.a; while (!atomicReference.compareAndSet(tob, tob2)) { if (atomicReference.get() != tob) { break; } } tob = tob2; break loop0; } boolean z = !tob.b.get() && tob.b.compareAndSet(false, true); try { fsq.c(tob); if (z) { this.b.subscribe(tob); } } catch (Throwable th) { C13147fSI.c(th); if (z) { tob.b.compareAndSet(true, false); } C13147fSI.c(th); throw fYR.c(th); } } /* loaded from: classes6.dex */ static final class tOB extends AtomicReference implements InterfaceC13174fSv, fSJ { private static Sts[] a = new Sts[0]; static final Sts[] d = new Sts[0]; final jbe c; private AtomicReference> h; private boolean j; final AtomicReference e = new AtomicReference<>(a); final AtomicBoolean b = new AtomicBoolean(); tOB(jbe jbeVar, AtomicReference> atomicReference) { this.c = jbeVar; this.h = atomicReference; } @Override // o.fSJ public final boolean isDisposed() { return this.e.get() == d; } @Override // o.fSJ public final void dispose() { this.e.set(d); AtomicReference> atomicReference = this.h; while (!atomicReference.compareAndSet(this, null) && atomicReference.get() == this) { } EnumC13192fTf.e(this); } final void b(Sts sts) { Sts[] stsArr; while (true) { Sts[] stsArr2 = this.e.get(); int length = stsArr2.length; if (length == 0) { return; } int i = 0; while (true) { if (i >= length) { i = -1; break; } else if (stsArr2[i].equals(sts)) { break; } else { i++; } } if (i < 0) { return; } if (length == 1) { stsArr = a; } else { Sts[] stsArr3 = new Sts[length - 1]; System.arraycopy(stsArr2, 0, stsArr3, 0, i); System.arraycopy(stsArr2, i + 1, stsArr3, i, (length - i) - 1); stsArr = stsArr3; } AtomicReference atomicReference = this.e; while (!atomicReference.compareAndSet(stsArr2, stsArr)) { if (atomicReference.get() != stsArr2) { break; } } return; } } @Override // o.InterfaceC13174fSv public final void onSubscribe(fSJ fsj) { if (EnumC13192fTf.a(this, fsj)) { b(); } } @Override // o.InterfaceC13174fSv public final void onNext(T t) { if (this.j) { return; } this.c.c(t); b(); } @Override // o.InterfaceC13174fSv public final void onError(Throwable th) { if (!this.j) { this.j = true; this.c.b(th); c(); return; } C13418fZu.c(th); } @Override // o.InterfaceC13174fSv public final void onComplete() { if (this.j) { return; } this.j = true; this.c.d(); c(); } private void b() { for (Sts sts : this.e.get()) { this.c.b(sts); } } private void c() { for (Sts sts : this.e.getAndSet(d)) { this.c.b(sts); } } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public static final class Sts extends AtomicInteger implements fSJ { Object a; private tOB b; private volatile boolean c; final InterfaceC13174fSv e; Sts(tOB tob, InterfaceC13174fSv interfaceC13174fSv) { this.b = tob; this.e = interfaceC13174fSv; } @Override // o.fSJ public final void dispose() { if (this.c) { return; } this.c = true; this.b.b(this); this.a = null; } @Override // o.fSJ public final boolean isDisposed() { return this.c; } } /* loaded from: classes6.dex */ static final class ZnX extends ArrayList implements jbe { private volatile int c; public ZnX() { super(16); } @Override // o.fWZ.jbe public final void c(T t) { add(fYX.d(t)); this.c++; } @Override // o.fWZ.jbe public final void b(Throwable th) { add(fYX.a(th)); this.c++; } @Override // o.fWZ.jbe public final void d() { add(fYX.c()); this.c++; } @Override // o.fWZ.jbe public final void b(Sts sts) { if (sts.getAndIncrement() != 0) { return; } InterfaceC13174fSv interfaceC13174fSv = sts.e; int i = 1; while (!sts.isDisposed()) { int i2 = this.c; Integer num = (Integer) sts.a; int intValue = num != null ? num.intValue() : 0; while (intValue < i2) { if (fYX.c(get(intValue), interfaceC13174fSv) || sts.isDisposed()) { return; } else { intValue++; } } sts.a = Integer.valueOf(intValue); i = sts.addAndGet(-i); if (i == 0) { return; } } } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public static final class ojQ extends AtomicReference { final Object c; ojQ(Object obj) { this.c = obj; } } /* loaded from: classes6.dex */ static abstract class RVV extends AtomicReference implements jbe { int a; private ojQ c; final boolean d; Object a(Object obj) { return obj; } abstract void a(); Object b(Object obj) { return obj; } RVV(boolean z) { this.d = z; ojQ ojq = new ojQ(null); this.c = ojq; set(ojq); } @Override // o.fWZ.jbe public final void c(T t) { ojQ ojq = new ojQ(b(fYX.d(t))); this.c.set(ojq); this.c = ojq; this.a++; a(); } @Override // o.fWZ.jbe public final void b(Throwable th) { ojQ ojq = new ojQ(b(fYX.a(th))); this.c.set(ojq); this.c = ojq; this.a++; c(); } @Override // o.fWZ.jbe public final void d() { ojQ ojq = new ojQ(b(fYX.c())); this.c.set(ojq); this.c = ojq; this.a++; c(); } @Override // o.fWZ.jbe public final void b(Sts sts) { if (sts.getAndIncrement() != 0) { return; } int i = 1; do { ojQ ojq = (ojQ) sts.a; if (ojq == null) { ojq = e(); sts.a = ojq; } while (!sts.isDisposed()) { ojQ ojq2 = ojq.get(); if (ojq2 != null) { if (fYX.c(a(ojq2.c), sts.e)) { sts.a = null; return; } ojq = ojq2; } else { sts.a = ojq; i = sts.addAndGet(-i); } } sts.a = null; return; } while (i != 0); } ojQ e() { return get(); } void c() { ojQ ojq = get(); if (ojq.c != null) { ojQ ojq2 = new ojQ(null); ojq2.lazySet(ojq.get()); set(ojq2); } } } /* loaded from: classes6.dex */ static final class dAO extends RVV { private int c; dAO(int i, boolean z) { super(z); this.c = i; } @Override // o.fWZ.RVV final void a() { if (this.a > this.c) { ojQ ojq = get().get(); this.a--; if (this.d) { ojQ ojq2 = new ojQ(null); ojq2.lazySet(ojq.get()); ojq = ojq2; } set(ojq); } } } /* loaded from: classes6.dex */ static final class NHB extends RVV { private AbstractC13173fSu b; private int c; private long e; private TimeUnit g; NHB(int i, long j, TimeUnit timeUnit, AbstractC13173fSu abstractC13173fSu, boolean z) { super(z); this.b = abstractC13173fSu; this.c = i; this.e = j; this.g = timeUnit; } @Override // o.fWZ.RVV final Object b(Object obj) { return new C13421fZx(obj, AbstractC13173fSu.b(this.g), this.g); } @Override // o.fWZ.RVV final Object a(Object obj) { return ((C13421fZx) obj).e; } @Override // o.fWZ.RVV final void a() { ojQ ojq; long b = AbstractC13173fSu.b(this.g); long j = this.e; ojQ ojq2 = get(); ojQ ojq3 = ojq2.get(); int i = 0; while (true) { ojQ ojq4 = ojq3; ojq = ojq2; ojq2 = ojq4; if (this.a > 1) { if (this.a <= this.c) { if (((C13421fZx) ojq2.c).d > b - j) { break; } i++; this.a--; ojq3 = ojq2.get(); } else { i++; this.a--; ojq3 = ojq2.get(); } } else { break; } } if (i != 0) { if (this.d) { ojQ ojq5 = new ojQ(null); ojq5.lazySet(ojq.get()); ojq = ojq5; } set(ojq); } } @Override // o.fWZ.RVV final void c() { ojQ ojq; long b = AbstractC13173fSu.b(this.g); long j = this.e; ojQ ojq2 = get(); ojQ ojq3 = ojq2.get(); int i = 0; while (true) { ojQ ojq4 = ojq3; ojq = ojq2; ojq2 = ojq4; if (this.a <= 1 || ((C13421fZx) ojq2.c).d > b - j) { break; } i++; this.a--; ojq3 = ojq2.get(); } if (i != 0) { if (this.d) { ojQ ojq5 = new ojQ(null); ojq5.lazySet(ojq.get()); ojq = ojq5; } set(ojq); } } @Override // o.fWZ.RVV final ojQ e() { ojQ ojq; long b = AbstractC13173fSu.b(this.g); long j = this.e; ojQ ojq2 = get(); ojQ ojq3 = ojq2.get(); while (true) { ojQ ojq4 = ojq3; ojq = ojq2; ojq2 = ojq4; if (ojq2 == null) { break; } C13421fZx c13421fZx = (C13421fZx) ojq2.c; if (fYX.e(c13421fZx.e) || fYX.b(c13421fZx.e) || c13421fZx.d > b - j) { break; } ojq3 = ojq2.get(); } return ojq; } } /* loaded from: classes6.dex */ static final class jNh implements HBt { jNh() { } @Override // o.fWZ.HBt public final jbe d() { return new ZnX(); } } /* loaded from: classes6.dex */ static final class LWm implements fSQ { private final fXV d; @Override // o.fSQ public final /* synthetic */ void c(fSJ fsj) throws Throwable { EnumC13192fTf.d((AtomicReference) this.d, fsj); } LWm(fXV fxv) { this.d = fxv; } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public static final class ZqN implements HBt { private int c; private boolean d; ZqN(int i, boolean z) { this.c = i; this.d = z; } @Override // o.fWZ.HBt public final jbe d() { return new dAO(this.c, this.d); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public static final class vUG implements HBt { private boolean a; private final AbstractC13173fSu b; private final TimeUnit c; private final int d; private final long e; vUG(int i, long j, TimeUnit timeUnit, AbstractC13173fSu abstractC13173fSu, boolean z) { this.d = i; this.e = j; this.c = timeUnit; this.b = abstractC13173fSu; this.a = z; } @Override // o.fWZ.HBt public final jbe d() { return new NHB(this.d, this.e, this.c, this.b, this.a); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public static final class saX implements InterfaceC13169fSq { private final AtomicReference> d; private final HBt e; saX(AtomicReference> atomicReference, HBt hBt) { this.d = atomicReference; this.e = hBt; } @Override // o.InterfaceC13169fSq public final void subscribe(InterfaceC13174fSv interfaceC13174fSv) { tOB tob; loop0: while (true) { tob = this.d.get(); if (tob != null) { break; } tOB tob2 = new tOB<>(this.e.d(), this.d); AtomicReference> atomicReference = this.d; while (!atomicReference.compareAndSet(null, tob2)) { if (atomicReference.get() != null) { break; } } tob = tob2; break loop0; } Sts sts = new Sts<>(tob, interfaceC13174fSv); interfaceC13174fSv.onSubscribe(sts); loop2: while (true) { Sts[] stsArr = tob.e.get(); if (stsArr == tOB.d) { break; } int length = stsArr.length; Sts[] stsArr2 = new Sts[length + 1]; System.arraycopy(stsArr, 0, stsArr2, 0, length); stsArr2[length] = sts; AtomicReference atomicReference2 = tob.e; while (!atomicReference2.compareAndSet(stsArr, stsArr2)) { if (atomicReference2.get() != stsArr) { break; } } break loop2; } if (sts.isDisposed()) { tob.b(sts); } else { tob.c.b(sts); } } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public static final class IeS extends AbstractC13163fSk { private final InterfaceC13189fTc> b; private final fSS, ? extends InterfaceC13169fSq> e; IeS(InterfaceC13189fTc> interfaceC13189fTc, fSS, ? extends InterfaceC13169fSq> fss) { this.b = interfaceC13189fTc; this.e = fss; } @Override // o.AbstractC13163fSk public final void subscribeActual(InterfaceC13174fSv interfaceC13174fSv) { try { fYZ fyz = (fYZ) Objects.requireNonNull(this.b.d(), "The connectableFactory returned a null ConnectableObservable"); InterfaceC13169fSq interfaceC13169fSq = (InterfaceC13169fSq) Objects.requireNonNull(this.e.a(fyz), "The selector returned a null ObservableSource"); fXV fxv = new fXV(interfaceC13174fSv); interfaceC13169fSq.subscribe(fxv); fyz.d(new LWm(fxv)); } catch (Throwable th) { C13147fSI.c(th); EnumC13195fTi.a(th, interfaceC13174fSv); } } } public static fYZ e(InterfaceC13169fSq interfaceC13169fSq, long j, TimeUnit timeUnit, AbstractC13173fSu abstractC13173fSu, boolean z) { vUG vug = new vUG(Integer.MAX_VALUE, j, timeUnit, abstractC13173fSu, z); AtomicReference atomicReference = new AtomicReference(); return new fWZ(new saX(atomicReference, vug), interfaceC13169fSq, atomicReference, vug); } public static fYZ c(InterfaceC13169fSq interfaceC13169fSq) { HBt hBt = d; AtomicReference atomicReference = new AtomicReference(); return new fWZ(new saX(atomicReference, hBt), interfaceC13169fSq, atomicReference, hBt); } }