package o; import java.util.ArrayDeque; import java.util.Iterator; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; /* renamed from: o.fXG, reason: case insensitive filesystem */ /* loaded from: classes6.dex */ public final class C13319fXG extends fUX> { private long a; private long b; private int e; public C13319fXG(InterfaceC13169fSq interfaceC13169fSq, long j, long j2, int i) { super(interfaceC13169fSq); this.b = j; this.a = j2; this.e = i; } @Override // o.AbstractC13163fSk public final void subscribeActual(InterfaceC13174fSv> interfaceC13174fSv) { if (this.b == this.a) { this.c.subscribe(new RVV(interfaceC13174fSv, this.b, this.e)); } else { this.c.subscribe(new Sts(interfaceC13174fSv, this.b, this.a, this.e)); } } /* renamed from: o.fXG$RVV */ /* loaded from: classes6.dex */ static final class RVV extends AtomicInteger implements InterfaceC13174fSv, fSJ, Runnable { private long a; private AtomicBoolean b = new AtomicBoolean(); private long c; private int d; private InterfaceC13174fSv> e; private C13423fZz g; private fSJ i; RVV(InterfaceC13174fSv> interfaceC13174fSv, long j, int i) { this.e = interfaceC13174fSv; this.c = j; this.d = i; lazySet(1); } @Override // o.InterfaceC13174fSv public final void onSubscribe(fSJ fsj) { if (EnumC13192fTf.d(this.i, fsj)) { this.i = fsj; this.e.onSubscribe(this); } } @Override // o.InterfaceC13174fSv public final void onNext(T t) { fXL fxl; C13423fZz c13423fZz = this.g; if (c13423fZz != null || this.b.get()) { fxl = null; } else { getAndIncrement(); c13423fZz = C13423fZz.b(this.d, this); this.g = c13423fZz; fxl = new fXL(c13423fZz); this.e.onNext(fxl); } if (c13423fZz != null) { c13423fZz.onNext(t); long j = this.a + 1; this.a = j; if (j >= this.c) { this.a = 0L; this.g = null; c13423fZz.onComplete(); } if (fxl == null || fxl.b.get() || !fxl.b.compareAndSet(false, true)) { return; } this.g = null; c13423fZz.onComplete(); } } @Override // o.InterfaceC13174fSv public final void onError(Throwable th) { C13423fZz c13423fZz = this.g; if (c13423fZz != null) { this.g = null; c13423fZz.onError(th); } this.e.onError(th); } @Override // o.InterfaceC13174fSv public final void onComplete() { C13423fZz c13423fZz = this.g; if (c13423fZz != null) { this.g = null; c13423fZz.onComplete(); } this.e.onComplete(); } @Override // o.fSJ public final void dispose() { if (this.b.compareAndSet(false, true)) { run(); } } @Override // o.fSJ public final boolean isDisposed() { return this.b.get(); } @Override // java.lang.Runnable public final void run() { if (decrementAndGet() == 0) { this.i.dispose(); } } } /* renamed from: o.fXG$Sts */ /* loaded from: classes6.dex */ static final class Sts extends AtomicInteger implements InterfaceC13174fSv, fSJ, Runnable { private long a; private long b; private int c; private InterfaceC13174fSv> e; private long f; private fSJ i; private long j; private ArrayDeque> h = new ArrayDeque<>(); private AtomicBoolean d = new AtomicBoolean(); Sts(InterfaceC13174fSv> interfaceC13174fSv, long j, long j2, int i) { this.e = interfaceC13174fSv; this.b = j; this.j = j2; this.c = i; lazySet(1); } @Override // o.InterfaceC13174fSv public final void onSubscribe(fSJ fsj) { if (EnumC13192fTf.d(this.i, fsj)) { this.i = fsj; this.e.onSubscribe(this); } } @Override // o.InterfaceC13174fSv public final void onNext(T t) { fXL fxl; ArrayDeque> arrayDeque = this.h; long j = this.f; long j2 = this.j; if (j % j2 != 0 || this.d.get()) { fxl = null; } else { getAndIncrement(); C13423fZz b = C13423fZz.b(this.c, this); fxl = new fXL(b); arrayDeque.offer(b); this.e.onNext(fxl); } long j3 = this.a + 1; Iterator> it = arrayDeque.iterator(); while (it.hasNext()) { it.next().onNext(t); } if (j3 >= this.b) { arrayDeque.poll().onComplete(); if (arrayDeque.isEmpty() && this.d.get()) { return; } else { j3 -= j2; } } this.a = j3; this.f = j + 1; if (fxl == null || fxl.b.get() || !fxl.b.compareAndSet(false, true)) { return; } fxl.a.onComplete(); } @Override // o.InterfaceC13174fSv public final void onError(Throwable th) { ArrayDeque> arrayDeque = this.h; while (!arrayDeque.isEmpty()) { arrayDeque.poll().onError(th); } this.e.onError(th); } @Override // o.InterfaceC13174fSv public final void onComplete() { ArrayDeque> arrayDeque = this.h; while (!arrayDeque.isEmpty()) { arrayDeque.poll().onComplete(); } this.e.onComplete(); } @Override // o.fSJ public final void dispose() { if (this.d.compareAndSet(false, true)) { run(); } } @Override // o.fSJ public final boolean isDisposed() { return this.d.get(); } @Override // java.lang.Runnable public final void run() { if (decrementAndGet() == 0) { this.i.dispose(); } } } }