alexandroid/decompiled/jadx/sources/io/reactivex/rxjava3/operators/SpscArrayQueue.java
KaKi87 a47fad5135 📦 Add decompiled Alexa 2.2.730155.0 (jadx, apktool, Hermes strings)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-07 00:04:16 +01:00

106 lines
3.3 KiB
Java

package io.reactivex.rxjava3.operators;
import io.reactivex.rxjava3.annotations.Nullable;
import io.reactivex.rxjava3.internal.util.Pow2;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReferenceArray;
import rx.Single$$ExternalSyntheticBUOutline0;
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
/* loaded from: classes10.dex */
public final class SpscArrayQueue<E> extends AtomicReferenceArray<E> implements SimplePlainQueue<E> {
private static final Integer MAX_LOOK_AHEAD_STEP = Integer.getInteger("jctools.spsc.max.lookahead.step", 4096);
private static final long serialVersionUID = -1296597691183856449L;
final AtomicLong consumerIndex;
final int lookAheadStep;
final int mask;
final AtomicLong producerIndex;
long producerLookAhead;
public SpscArrayQueue(int i) {
super(Pow2.roundToPowerOfTwo(i));
this.mask = length() - 1;
this.producerIndex = new AtomicLong();
this.consumerIndex = new AtomicLong();
this.lookAheadStep = Math.min(i / 4, MAX_LOOK_AHEAD_STEP.intValue());
}
public int calcElementOffset(long j) {
return this.mask & ((int) j);
}
@Override // io.reactivex.rxjava3.operators.SimpleQueue
public void clear() {
while (true) {
if (poll() == null && isEmpty()) {
return;
}
}
}
@Override // io.reactivex.rxjava3.operators.SimpleQueue
public boolean isEmpty() {
return this.producerIndex.get() == this.consumerIndex.get();
}
public E lvElement(int i) {
return get(i);
}
@Override // io.reactivex.rxjava3.operators.SimpleQueue
public boolean offer(E e) {
if (e == null) {
Single$$ExternalSyntheticBUOutline0.m$1("Null is not a valid element");
return false;
}
int i = this.mask;
long j = this.producerIndex.get();
int calcElementOffset = calcElementOffset(j, i);
if (j >= this.producerLookAhead) {
long j2 = this.lookAheadStep + j;
if (lvElement(calcElementOffset(j2, i)) == null) {
this.producerLookAhead = j2;
} else if (lvElement(calcElementOffset) != null) {
return false;
}
}
soElement(calcElementOffset, e);
soProducerIndex(j + 1);
return true;
}
@Override // io.reactivex.rxjava3.operators.SimplePlainQueue, io.reactivex.rxjava3.operators.SimpleQueue
@Nullable
public E poll() {
long j = this.consumerIndex.get();
int calcElementOffset = calcElementOffset(j);
E lvElement = lvElement(calcElementOffset);
if (lvElement == null) {
return null;
}
soConsumerIndex(j + 1);
soElement(calcElementOffset, null);
return lvElement;
}
public void soConsumerIndex(long j) {
this.consumerIndex.lazySet(j);
}
public void soElement(int i, E e) {
lazySet(i, e);
}
public void soProducerIndex(long j) {
this.producerIndex.lazySet(j);
}
public int calcElementOffset(long j, int i) {
return ((int) j) & i;
}
@Override // io.reactivex.rxjava3.operators.SimpleQueue
public boolean offer(E e, E e2) {
return offer(e) && offer(e2);
}
}