Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,111 @@
package io.reactivex.internal.queue;
import io.reactivex.internal.fuseable.SimplePlainQueue;
import java.util.concurrent.atomic.AtomicReference;
/* loaded from: classes2.dex */
public final class MpscLinkedQueue<T> implements SimplePlainQueue<T> {
private final AtomicReference<LinkedQueueNode<T>> a = new AtomicReference<>();
private final AtomicReference<LinkedQueueNode<T>> b = new AtomicReference<>();
static final class LinkedQueueNode<E> extends AtomicReference<LinkedQueueNode<E>> {
private E a;
LinkedQueueNode() {
}
public E a() {
E b = b();
a((LinkedQueueNode<E>) null);
return b;
}
public E b() {
return this.a;
}
public LinkedQueueNode<E> c() {
return get();
}
LinkedQueueNode(E e) {
a((LinkedQueueNode<E>) e);
}
public void a(E e) {
this.a = e;
}
public void a(LinkedQueueNode<E> linkedQueueNode) {
lazySet(linkedQueueNode);
}
}
public MpscLinkedQueue() {
LinkedQueueNode<T> linkedQueueNode = new LinkedQueueNode<>();
a(linkedQueueNode);
b(linkedQueueNode);
}
LinkedQueueNode<T> a() {
return this.b.get();
}
LinkedQueueNode<T> b(LinkedQueueNode<T> linkedQueueNode) {
return this.a.getAndSet(linkedQueueNode);
}
LinkedQueueNode<T> c() {
return this.a.get();
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public void clear() {
while (poll() != null && !isEmpty()) {
}
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public boolean isEmpty() {
return b() == c();
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public boolean offer(T t) {
if (t == null) {
throw new NullPointerException("Null is not a valid element");
}
LinkedQueueNode<T> linkedQueueNode = new LinkedQueueNode<>(t);
b(linkedQueueNode).a(linkedQueueNode);
return true;
}
@Override // io.reactivex.internal.fuseable.SimplePlainQueue, io.reactivex.internal.fuseable.SimpleQueue
public T poll() {
LinkedQueueNode<T> c;
LinkedQueueNode<T> a = a();
LinkedQueueNode<T> c2 = a.c();
if (c2 != null) {
T a2 = c2.a();
a(c2);
return a2;
}
if (a == c()) {
return null;
}
do {
c = a.c();
} while (c == null);
T a3 = c.a();
a(c);
return a3;
}
void a(LinkedQueueNode<T> linkedQueueNode) {
this.b.lazySet(linkedQueueNode);
}
LinkedQueueNode<T> b() {
return this.b.get();
}
}

View File

@@ -0,0 +1,102 @@
package io.reactivex.internal.queue;
import com.ubt.jimu.base.util.FileUtil;
import io.reactivex.internal.fuseable.SimplePlainQueue;
import io.reactivex.internal.util.Pow2;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReferenceArray;
/* loaded from: classes2.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", FileUtil.ZIP_BUFFER_SIZE);
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.a(i));
this.mask = length() - 1;
this.producerIndex = new AtomicLong();
this.consumerIndex = new AtomicLong();
this.lookAheadStep = Math.min(i / 4, MAX_LOOK_AHEAD_STEP.intValue());
}
int calcElementOffset(long j) {
return this.mask & ((int) j);
}
int calcElementOffset(long j, int i) {
return ((int) j) & i;
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public void clear() {
while (true) {
if (poll() == null && isEmpty()) {
return;
}
}
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public boolean isEmpty() {
return this.producerIndex.get() == this.consumerIndex.get();
}
E lvElement(int i) {
return get(i);
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public boolean offer(E e) {
if (e == null) {
throw new NullPointerException("Null is not a valid element");
}
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.internal.fuseable.SimplePlainQueue, io.reactivex.internal.fuseable.SimpleQueue
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;
}
void soConsumerIndex(long j) {
this.consumerIndex.lazySet(j);
}
void soElement(int i, E e) {
lazySet(i, e);
}
void soProducerIndex(long j) {
this.producerIndex.lazySet(j);
}
public boolean offer(E e, E e2) {
return offer(e) && offer(e2);
}
}

View File

@@ -0,0 +1,225 @@
package io.reactivex.internal.queue;
import com.ubt.jimu.base.util.FileUtil;
import io.reactivex.internal.fuseable.SimplePlainQueue;
import io.reactivex.internal.util.Pow2;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReferenceArray;
/* loaded from: classes2.dex */
public final class SpscLinkedArrayQueue<T> implements SimplePlainQueue<T> {
static final int i = Integer.getInteger("jctools.spsc.max.lookahead.step", FileUtil.ZIP_BUFFER_SIZE).intValue();
private static final Object j = new Object();
int b;
long c;
final int d;
AtomicReferenceArray<Object> e;
final int f;
AtomicReferenceArray<Object> g;
final AtomicLong a = new AtomicLong();
final AtomicLong h = new AtomicLong();
public SpscLinkedArrayQueue(int i2) {
int a = Pow2.a(Math.max(8, i2));
int i3 = a - 1;
AtomicReferenceArray<Object> atomicReferenceArray = new AtomicReferenceArray<>(a + 1);
this.e = atomicReferenceArray;
this.d = i3;
a(a);
this.g = atomicReferenceArray;
this.f = i3;
this.c = i3 - 1;
b(0L);
}
private boolean a(AtomicReferenceArray<Object> atomicReferenceArray, T t, long j2, int i2) {
a(atomicReferenceArray, i2, t);
b(j2 + 1);
return true;
}
private static int b(int i2) {
return i2;
}
private AtomicReferenceArray<Object> b(AtomicReferenceArray<Object> atomicReferenceArray, int i2) {
b(i2);
AtomicReferenceArray<Object> atomicReferenceArray2 = (AtomicReferenceArray) a(atomicReferenceArray, i2);
a(atomicReferenceArray, i2, (Object) null);
return atomicReferenceArray2;
}
private long c() {
return this.h.get();
}
private long d() {
return this.a.get();
}
private long e() {
return this.h.get();
}
private long f() {
return this.a.get();
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public void clear() {
while (true) {
if (poll() == null && isEmpty()) {
return;
}
}
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public boolean isEmpty() {
return f() == e();
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public boolean offer(T t) {
if (t == null) {
throw new NullPointerException("Null is not a valid element");
}
AtomicReferenceArray<Object> atomicReferenceArray = this.e;
long d = d();
int i2 = this.d;
int a = a(d, i2);
if (d < this.c) {
return a(atomicReferenceArray, t, d, a);
}
long j2 = this.b + d;
if (a(atomicReferenceArray, a(j2, i2)) == null) {
this.c = j2 - 1;
return a(atomicReferenceArray, t, d, a);
}
if (a(atomicReferenceArray, a(1 + d, i2)) == null) {
return a(atomicReferenceArray, t, d, a);
}
a(atomicReferenceArray, d, a, t, i2);
return true;
}
@Override // io.reactivex.internal.fuseable.SimplePlainQueue, io.reactivex.internal.fuseable.SimpleQueue
public T poll() {
AtomicReferenceArray<Object> atomicReferenceArray = this.g;
long c = c();
int i2 = this.f;
int a = a(c, i2);
T t = (T) a(atomicReferenceArray, a);
boolean z = t == j;
if (t == null || z) {
if (z) {
return b(b(atomicReferenceArray, i2 + 1), c, i2);
}
return null;
}
a(atomicReferenceArray, a, (Object) null);
a(c + 1);
return t;
}
private void a(AtomicReferenceArray<Object> atomicReferenceArray, long j2, int i2, T t, long j3) {
AtomicReferenceArray<Object> atomicReferenceArray2 = new AtomicReferenceArray<>(atomicReferenceArray.length());
this.e = atomicReferenceArray2;
this.c = (j3 + j2) - 1;
a(atomicReferenceArray2, i2, t);
a(atomicReferenceArray, atomicReferenceArray2);
a(atomicReferenceArray, i2, j);
b(j2 + 1);
}
private T b(AtomicReferenceArray<Object> atomicReferenceArray, long j2, int i2) {
this.g = atomicReferenceArray;
int a = a(j2, i2);
T t = (T) a(atomicReferenceArray, a);
if (t != null) {
a(atomicReferenceArray, a, (Object) null);
a(j2 + 1);
}
return t;
}
public int b() {
long e = e();
while (true) {
long f = f();
long e2 = e();
if (e == e2) {
return (int) (f - e2);
}
e = e2;
}
}
private void a(AtomicReferenceArray<Object> atomicReferenceArray, AtomicReferenceArray<Object> atomicReferenceArray2) {
int length = atomicReferenceArray.length() - 1;
b(length);
a(atomicReferenceArray, length, atomicReferenceArray2);
}
private void b(long j2) {
this.a.lazySet(j2);
}
public T a() {
AtomicReferenceArray<Object> atomicReferenceArray = this.g;
long c = c();
int i2 = this.f;
T t = (T) a(atomicReferenceArray, a(c, i2));
return t == j ? a(b(atomicReferenceArray, i2 + 1), c, i2) : t;
}
private T a(AtomicReferenceArray<Object> atomicReferenceArray, long j2, int i2) {
this.g = atomicReferenceArray;
return (T) a(atomicReferenceArray, a(j2, i2));
}
private void a(int i2) {
this.b = Math.min(i2 / 4, i);
}
private void a(long j2) {
this.h.lazySet(j2);
}
private static int a(long j2, int i2) {
int i3 = ((int) j2) & i2;
b(i3);
return i3;
}
private static void a(AtomicReferenceArray<Object> atomicReferenceArray, int i2, Object obj) {
atomicReferenceArray.lazySet(i2, obj);
}
private static <E> Object a(AtomicReferenceArray<Object> atomicReferenceArray, int i2) {
return atomicReferenceArray.get(i2);
}
public boolean a(T t, T t2) {
AtomicReferenceArray<Object> atomicReferenceArray = this.e;
long f = f();
int i2 = this.d;
long j2 = 2 + f;
if (a(atomicReferenceArray, a(j2, i2)) == null) {
int a = a(f, i2);
a(atomicReferenceArray, a + 1, t2);
a(atomicReferenceArray, a, t);
b(j2);
return true;
}
AtomicReferenceArray<Object> atomicReferenceArray2 = new AtomicReferenceArray<>(atomicReferenceArray.length());
this.e = atomicReferenceArray2;
int a2 = a(f, i2);
a(atomicReferenceArray2, a2 + 1, t2);
a(atomicReferenceArray2, a2, t);
a(atomicReferenceArray, atomicReferenceArray2);
a(atomicReferenceArray, a2, j);
b(j2);
return true;
}
}