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,177 @@
package io.reactivex.subjects;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.internal.functions.ObjectHelper;
import io.reactivex.plugins.RxJavaPlugins;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
/* loaded from: classes2.dex */
public final class PublishSubject<T> extends Subject<T> {
static final PublishDisposable[] c = new PublishDisposable[0];
static final PublishDisposable[] d = new PublishDisposable[0];
final AtomicReference<PublishDisposable<T>[]> a = new AtomicReference<>(d);
Throwable b;
PublishSubject() {
}
public static <T> PublishSubject<T> b() {
return new PublishSubject<>();
}
boolean a(PublishDisposable<T> publishDisposable) {
PublishDisposable<T>[] publishDisposableArr;
PublishDisposable<T>[] publishDisposableArr2;
do {
publishDisposableArr = this.a.get();
if (publishDisposableArr == c) {
return false;
}
int length = publishDisposableArr.length;
publishDisposableArr2 = new PublishDisposable[length + 1];
System.arraycopy(publishDisposableArr, 0, publishDisposableArr2, 0, length);
publishDisposableArr2[length] = publishDisposable;
} while (!this.a.compareAndSet(publishDisposableArr, publishDisposableArr2));
return true;
}
@Override // io.reactivex.Observer
public void onComplete() {
PublishDisposable<T>[] publishDisposableArr = this.a.get();
PublishDisposable<T>[] publishDisposableArr2 = c;
if (publishDisposableArr == publishDisposableArr2) {
return;
}
for (PublishDisposable<T> publishDisposable : this.a.getAndSet(publishDisposableArr2)) {
publishDisposable.b();
}
}
@Override // io.reactivex.Observer
public void onError(Throwable th) {
ObjectHelper.a(th, "onError called with null. Null values are generally not allowed in 2.x operators and sources.");
PublishDisposable<T>[] publishDisposableArr = this.a.get();
PublishDisposable<T>[] publishDisposableArr2 = c;
if (publishDisposableArr == publishDisposableArr2) {
RxJavaPlugins.b(th);
return;
}
this.b = th;
for (PublishDisposable<T> publishDisposable : this.a.getAndSet(publishDisposableArr2)) {
publishDisposable.a(th);
}
}
@Override // io.reactivex.Observer
public void onNext(T t) {
ObjectHelper.a((Object) t, "onNext called with null. Null values are generally not allowed in 2.x operators and sources.");
for (PublishDisposable<T> publishDisposable : this.a.get()) {
publishDisposable.a((PublishDisposable<T>) t);
}
}
@Override // io.reactivex.Observer
public void onSubscribe(Disposable disposable) {
if (this.a.get() == c) {
disposable.dispose();
}
}
@Override // io.reactivex.Observable
protected void subscribeActual(Observer<? super T> observer) {
PublishDisposable<T> publishDisposable = new PublishDisposable<>(observer, this);
observer.onSubscribe(publishDisposable);
if (a(publishDisposable)) {
if (publishDisposable.a()) {
b(publishDisposable);
}
} else {
Throwable th = this.b;
if (th != null) {
observer.onError(th);
} else {
observer.onComplete();
}
}
}
static final class PublishDisposable<T> extends AtomicBoolean implements Disposable {
final Observer<? super T> a;
final PublishSubject<T> b;
PublishDisposable(Observer<? super T> observer, PublishSubject<T> publishSubject) {
this.a = observer;
this.b = publishSubject;
}
public void a(T t) {
if (get()) {
return;
}
this.a.onNext(t);
}
public void b() {
if (get()) {
return;
}
this.a.onComplete();
}
@Override // io.reactivex.disposables.Disposable
public void dispose() {
if (compareAndSet(false, true)) {
this.b.b(this);
}
}
public void a(Throwable th) {
if (get()) {
RxJavaPlugins.b(th);
} else {
this.a.onError(th);
}
}
public boolean a() {
return get();
}
}
void b(PublishDisposable<T> publishDisposable) {
PublishDisposable<T>[] publishDisposableArr;
PublishDisposable<T>[] publishDisposableArr2;
do {
publishDisposableArr = this.a.get();
if (publishDisposableArr == c || publishDisposableArr == d) {
return;
}
int length = publishDisposableArr.length;
int i = -1;
int i2 = 0;
while (true) {
if (i2 >= length) {
break;
}
if (publishDisposableArr[i2] == publishDisposable) {
i = i2;
break;
}
i2++;
}
if (i < 0) {
return;
}
if (length == 1) {
publishDisposableArr2 = d;
} else {
PublishDisposable<T>[] publishDisposableArr3 = new PublishDisposable[length - 1];
System.arraycopy(publishDisposableArr, 0, publishDisposableArr3, 0, i);
System.arraycopy(publishDisposableArr, i + 1, publishDisposableArr3, i, (length - i) - 1);
publishDisposableArr2 = publishDisposableArr3;
}
} while (!this.a.compareAndSet(publishDisposableArr, publishDisposableArr2));
}
}

View File

@@ -0,0 +1,152 @@
package io.reactivex.subjects;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.internal.util.AppendOnlyLinkedArrayList;
import io.reactivex.internal.util.NotificationLite;
import io.reactivex.plugins.RxJavaPlugins;
/* loaded from: classes2.dex */
final class SerializedSubject<T> extends Subject<T> implements AppendOnlyLinkedArrayList.NonThrowingPredicate<Object> {
final Subject<T> a;
boolean b;
AppendOnlyLinkedArrayList<Object> c;
volatile boolean d;
SerializedSubject(Subject<T> subject) {
this.a = subject;
}
@Override // io.reactivex.internal.util.AppendOnlyLinkedArrayList.NonThrowingPredicate, io.reactivex.functions.Predicate
public boolean a(Object obj) {
return NotificationLite.acceptFull(obj, this.a);
}
void b() {
AppendOnlyLinkedArrayList<Object> appendOnlyLinkedArrayList;
while (true) {
synchronized (this) {
appendOnlyLinkedArrayList = this.c;
if (appendOnlyLinkedArrayList == null) {
this.b = false;
return;
}
this.c = null;
}
appendOnlyLinkedArrayList.a((AppendOnlyLinkedArrayList.NonThrowingPredicate<? super Object>) this);
}
}
@Override // io.reactivex.Observer
public void onComplete() {
if (this.d) {
return;
}
synchronized (this) {
if (this.d) {
return;
}
this.d = true;
if (!this.b) {
this.b = true;
this.a.onComplete();
return;
}
AppendOnlyLinkedArrayList<Object> appendOnlyLinkedArrayList = this.c;
if (appendOnlyLinkedArrayList == null) {
appendOnlyLinkedArrayList = new AppendOnlyLinkedArrayList<>(4);
this.c = appendOnlyLinkedArrayList;
}
appendOnlyLinkedArrayList.a((AppendOnlyLinkedArrayList<Object>) NotificationLite.complete());
}
}
@Override // io.reactivex.Observer
public void onError(Throwable th) {
boolean z;
if (this.d) {
RxJavaPlugins.b(th);
return;
}
synchronized (this) {
if (this.d) {
z = true;
} else {
this.d = true;
if (this.b) {
AppendOnlyLinkedArrayList<Object> appendOnlyLinkedArrayList = this.c;
if (appendOnlyLinkedArrayList == null) {
appendOnlyLinkedArrayList = new AppendOnlyLinkedArrayList<>(4);
this.c = appendOnlyLinkedArrayList;
}
appendOnlyLinkedArrayList.b(NotificationLite.error(th));
return;
}
z = false;
this.b = true;
}
if (z) {
RxJavaPlugins.b(th);
} else {
this.a.onError(th);
}
}
}
@Override // io.reactivex.Observer
public void onNext(T t) {
if (this.d) {
return;
}
synchronized (this) {
if (this.d) {
return;
}
if (!this.b) {
this.b = true;
this.a.onNext(t);
b();
} else {
AppendOnlyLinkedArrayList<Object> appendOnlyLinkedArrayList = this.c;
if (appendOnlyLinkedArrayList == null) {
appendOnlyLinkedArrayList = new AppendOnlyLinkedArrayList<>(4);
this.c = appendOnlyLinkedArrayList;
}
appendOnlyLinkedArrayList.a((AppendOnlyLinkedArrayList<Object>) NotificationLite.next(t));
}
}
}
@Override // io.reactivex.Observer
public void onSubscribe(Disposable disposable) {
boolean z = true;
if (!this.d) {
synchronized (this) {
if (!this.d) {
if (this.b) {
AppendOnlyLinkedArrayList<Object> appendOnlyLinkedArrayList = this.c;
if (appendOnlyLinkedArrayList == null) {
appendOnlyLinkedArrayList = new AppendOnlyLinkedArrayList<>(4);
this.c = appendOnlyLinkedArrayList;
}
appendOnlyLinkedArrayList.a((AppendOnlyLinkedArrayList<Object>) NotificationLite.disposable(disposable));
return;
}
this.b = true;
z = false;
}
}
}
if (z) {
disposable.dispose();
} else {
this.a.onSubscribe(disposable);
b();
}
}
@Override // io.reactivex.Observable
protected void subscribeActual(Observer<? super T> observer) {
this.a.subscribe(observer);
}
}

View File

@@ -0,0 +1,11 @@
package io.reactivex.subjects;
import io.reactivex.Observable;
import io.reactivex.Observer;
/* loaded from: classes2.dex */
public abstract class Subject<T> extends Observable<T> implements Observer<T> {
public final Subject<T> a() {
return this instanceof SerializedSubject ? this : new SerializedSubject(this);
}
}

View File

@@ -0,0 +1,268 @@
package io.reactivex.subjects;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import io.reactivex.internal.disposables.EmptyDisposable;
import io.reactivex.internal.functions.ObjectHelper;
import io.reactivex.internal.fuseable.SimpleQueue;
import io.reactivex.internal.observers.BasicIntQueueDisposable;
import io.reactivex.internal.queue.SpscLinkedArrayQueue;
import io.reactivex.plugins.RxJavaPlugins;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
/* loaded from: classes2.dex */
public final class UnicastSubject<T> extends Subject<T> {
final SpscLinkedArrayQueue<T> a;
final AtomicReference<Observer<? super T>> b;
final AtomicReference<Runnable> c;
final boolean d;
volatile boolean e;
volatile boolean f;
Throwable g;
final AtomicBoolean h;
final BasicIntQueueDisposable<T> i;
boolean j;
final class UnicastQueueDisposable extends BasicIntQueueDisposable<T> {
UnicastQueueDisposable() {
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public void clear() {
UnicastSubject.this.a.clear();
}
@Override // io.reactivex.disposables.Disposable
public void dispose() {
if (UnicastSubject.this.e) {
return;
}
UnicastSubject unicastSubject = UnicastSubject.this;
unicastSubject.e = true;
unicastSubject.b();
UnicastSubject.this.b.lazySet(null);
if (UnicastSubject.this.i.getAndIncrement() == 0) {
UnicastSubject.this.b.lazySet(null);
UnicastSubject.this.a.clear();
}
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public boolean isEmpty() {
return UnicastSubject.this.a.isEmpty();
}
@Override // io.reactivex.internal.fuseable.SimpleQueue
public T poll() throws Exception {
return UnicastSubject.this.a.poll();
}
@Override // io.reactivex.internal.fuseable.QueueFuseable
public int requestFusion(int i) {
if ((i & 2) == 0) {
return 0;
}
UnicastSubject.this.j = true;
return 2;
}
}
UnicastSubject(int i, boolean z) {
ObjectHelper.a(i, "capacityHint");
this.a = new SpscLinkedArrayQueue<>(i);
this.c = new AtomicReference<>();
this.d = z;
this.b = new AtomicReference<>();
this.h = new AtomicBoolean();
this.i = new UnicastQueueDisposable();
}
public static <T> UnicastSubject<T> a(int i) {
return new UnicastSubject<>(i, true);
}
public static <T> UnicastSubject<T> d() {
return new UnicastSubject<>(Observable.bufferSize(), true);
}
void b() {
Runnable runnable = this.c.get();
if (runnable == null || !this.c.compareAndSet(runnable, null)) {
return;
}
runnable.run();
}
void c(Observer<? super T> observer) {
this.b.lazySet(null);
Throwable th = this.g;
if (th != null) {
observer.onError(th);
} else {
observer.onComplete();
}
}
@Override // io.reactivex.Observer
public void onComplete() {
if (this.f || this.e) {
return;
}
this.f = true;
b();
c();
}
@Override // io.reactivex.Observer
public void onError(Throwable th) {
ObjectHelper.a(th, "onError called with null. Null values are generally not allowed in 2.x operators and sources.");
if (this.f || this.e) {
RxJavaPlugins.b(th);
return;
}
this.g = th;
this.f = true;
b();
c();
}
@Override // io.reactivex.Observer
public void onNext(T t) {
ObjectHelper.a((Object) t, "onNext called with null. Null values are generally not allowed in 2.x operators and sources.");
if (this.f || this.e) {
return;
}
this.a.offer(t);
c();
}
@Override // io.reactivex.Observer
public void onSubscribe(Disposable disposable) {
if (this.f || this.e) {
disposable.dispose();
}
}
@Override // io.reactivex.Observable
protected void subscribeActual(Observer<? super T> observer) {
if (this.h.get() || !this.h.compareAndSet(false, true)) {
EmptyDisposable.error(new IllegalStateException("Only a single observer allowed."), observer);
return;
}
observer.onSubscribe(this.i);
this.b.lazySet(observer);
if (this.e) {
this.b.lazySet(null);
} else {
c();
}
}
public static <T> UnicastSubject<T> a(int i, Runnable runnable) {
return new UnicastSubject<>(i, runnable, true);
}
void a(Observer<? super T> observer) {
SpscLinkedArrayQueue<T> spscLinkedArrayQueue = this.a;
int i = 1;
boolean z = !this.d;
while (!this.e) {
boolean z2 = this.f;
if (z && z2 && a(spscLinkedArrayQueue, observer)) {
return;
}
observer.onNext(null);
if (z2) {
c(observer);
return;
} else {
i = this.i.addAndGet(-i);
if (i == 0) {
return;
}
}
}
this.b.lazySet(null);
spscLinkedArrayQueue.clear();
}
void b(Observer<? super T> observer) {
SpscLinkedArrayQueue<T> spscLinkedArrayQueue = this.a;
boolean z = !this.d;
boolean z2 = true;
int i = 1;
while (!this.e) {
boolean z3 = this.f;
T poll = this.a.poll();
boolean z4 = poll == null;
if (z3) {
if (z && z2) {
if (a(spscLinkedArrayQueue, observer)) {
return;
} else {
z2 = false;
}
}
if (z4) {
c(observer);
return;
}
}
if (z4) {
i = this.i.addAndGet(-i);
if (i == 0) {
return;
}
} else {
observer.onNext(poll);
}
}
this.b.lazySet(null);
spscLinkedArrayQueue.clear();
}
void c() {
if (this.i.getAndIncrement() != 0) {
return;
}
Observer<? super T> observer = this.b.get();
int i = 1;
while (observer == null) {
i = this.i.addAndGet(-i);
if (i == 0) {
return;
} else {
observer = this.b.get();
}
}
if (this.j) {
a(observer);
} else {
b(observer);
}
}
UnicastSubject(int i, Runnable runnable, boolean z) {
ObjectHelper.a(i, "capacityHint");
this.a = new SpscLinkedArrayQueue<>(i);
ObjectHelper.a(runnable, "onTerminate");
this.c = new AtomicReference<>(runnable);
this.d = z;
this.b = new AtomicReference<>();
this.h = new AtomicBoolean();
this.i = new UnicastQueueDisposable();
}
boolean a(SimpleQueue<T> simpleQueue, Observer<? super T> observer) {
Throwable th = this.g;
if (th == null) {
return false;
}
this.b.lazySet(null);
simpleQueue.clear();
observer.onError(th);
return true;
}
}