153 lines
5.0 KiB
Java
153 lines
5.0 KiB
Java
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);
|
|
}
|
|
}
|