package o; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; /* renamed from: o.fVo, reason: case insensitive filesystem */ /* loaded from: classes6.dex */ public final class C13271fVo extends fUX implements InterfaceC13174fSv { final Sts b; final AtomicReference[]> d; private volatile boolean f; private AtomicBoolean g; private int h; private volatile long i; private Throwable j; private Sts l; /* renamed from: o, reason: collision with root package name */ private int f9116o; static final LWm[] e = new LWm[0]; private static LWm[] a = new LWm[0]; @Override // o.InterfaceC13174fSv public final void onSubscribe(fSJ fsj) { } public C13271fVo(AbstractC13163fSk abstractC13163fSk, int i) { super(abstractC13163fSk); this.h = i; this.g = new AtomicBoolean(); Sts sts = new Sts<>(i); this.b = sts; this.l = sts; this.d = new AtomicReference<>(e); } @Override // o.AbstractC13163fSk public final void subscribeActual(InterfaceC13174fSv interfaceC13174fSv) { LWm lWm = new LWm<>(interfaceC13174fSv, this); interfaceC13174fSv.onSubscribe(lWm); loop0: while (true) { LWm[] lWmArr = this.d.get(); if (lWmArr == a) { break; } int length = lWmArr.length; LWm[] lWmArr2 = new LWm[length + 1]; System.arraycopy(lWmArr, 0, lWmArr2, 0, length); lWmArr2[length] = lWm; AtomicReference[]> atomicReference = this.d; while (!atomicReference.compareAndSet(lWmArr, lWmArr2)) { if (atomicReference.get() != lWmArr) { break; } } break loop0; } if (!this.g.get() && this.g.compareAndSet(false, true)) { this.c.subscribe(this); } else { b(lWm); } } private void b(LWm lWm) { if (lWm.getAndIncrement() != 0) { return; } long j = lWm.a; int i = lWm.e; Sts sts = lWm.d; InterfaceC13174fSv interfaceC13174fSv = lWm.c; int i2 = this.h; int i3 = 1; while (!lWm.b) { boolean z = this.f; boolean z2 = this.i == j; if (z && z2) { lWm.d = null; Throwable th = this.j; if (th != null) { interfaceC13174fSv.onError(th); return; } else { interfaceC13174fSv.onComplete(); return; } } if (!z2) { if (i == i2) { sts = sts.e; i = 0; } interfaceC13174fSv.onNext(sts.b[i]); i++; j++; } else { lWm.a = j; lWm.e = i; lWm.d = sts; i3 = lWm.addAndGet(-i3); if (i3 == 0) { return; } } } lWm.d = null; } @Override // o.InterfaceC13174fSv public final void onNext(T t) { int i = this.f9116o; if (i == this.h) { Sts sts = new Sts<>(i); sts.b[0] = t; this.f9116o = 1; this.l.e = sts; this.l = sts; } else { this.l.b[i] = t; this.f9116o = i + 1; } this.i++; for (LWm lWm : this.d.get()) { b(lWm); } } @Override // o.InterfaceC13174fSv public final void onError(Throwable th) { this.j = th; this.f = true; for (LWm lWm : this.d.getAndSet(a)) { b(lWm); } } @Override // o.InterfaceC13174fSv public final void onComplete() { this.f = true; for (LWm lWm : this.d.getAndSet(a)) { b(lWm); } } /* JADX INFO: Access modifiers changed from: package-private */ /* renamed from: o.fVo$LWm */ /* loaded from: classes6.dex */ public static final class LWm extends AtomicInteger implements fSJ { long a; volatile boolean b; final InterfaceC13174fSv c; Sts d; int e; private C13271fVo h; LWm(InterfaceC13174fSv interfaceC13174fSv, C13271fVo c13271fVo) { this.c = interfaceC13174fSv; this.h = c13271fVo; this.d = c13271fVo.b; } @Override // o.fSJ public final void dispose() { LWm[] lWmArr; if (this.b) { return; } this.b = true; C13271fVo c13271fVo = this.h; while (true) { LWm[] lWmArr2 = c13271fVo.d.get(); int length = lWmArr2.length; if (length != 0) { int i = 0; while (true) { if (i >= length) { i = -1; break; } else if (lWmArr2[i] == this) { break; } else { i++; } } if (i >= 0) { if (length == 1) { lWmArr = C13271fVo.e; } else { LWm[] lWmArr3 = new LWm[length - 1]; System.arraycopy(lWmArr2, 0, lWmArr3, 0, i); System.arraycopy(lWmArr2, i + 1, lWmArr3, i, (length - i) - 1); lWmArr = lWmArr3; } AtomicReference[]> atomicReference = c13271fVo.d; while (!atomicReference.compareAndSet(lWmArr2, lWmArr)) { if (atomicReference.get() != lWmArr2) { break; } } return; } return; } return; } } @Override // o.fSJ public final boolean isDisposed() { return this.b; } } /* JADX INFO: Access modifiers changed from: package-private */ /* renamed from: o.fVo$Sts */ /* loaded from: classes6.dex */ public static final class Sts { final T[] b; volatile Sts e; Sts(int i) { this.b = (T[]) new Object[i]; } } }