mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-14 09:57:16 +01:00
162 lines
5.6 KiB
Java
162 lines
5.6 KiB
Java
package io.reactivex.rxjava3.internal.subscriptions;
|
|
|
|
import androidx.compose.animation.core.ArcMode$$ExternalSyntheticOutline0;
|
|
import io.reactivex.rxjava3.exceptions.ProtocolViolationException;
|
|
import io.reactivex.rxjava3.internal.util.BackpressureHelper;
|
|
import io.reactivex.rxjava3.plugins.RxJavaPlugins;
|
|
import java.util.Objects;
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import org.reactivestreams.Subscription;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes10.dex */
|
|
public enum SubscriptionHelper implements Subscription {
|
|
CANCELLED;
|
|
|
|
public static boolean cancel(AtomicReference<Subscription> atomicReference) {
|
|
Subscription andSet;
|
|
Subscription subscription = atomicReference.get();
|
|
SubscriptionHelper subscriptionHelper = CANCELLED;
|
|
if (subscription == subscriptionHelper || (andSet = atomicReference.getAndSet(subscriptionHelper)) == subscriptionHelper) {
|
|
return false;
|
|
}
|
|
if (andSet == null) {
|
|
return true;
|
|
}
|
|
andSet.cancel();
|
|
return true;
|
|
}
|
|
|
|
public static void deferredRequest(AtomicReference<Subscription> atomicReference, AtomicLong atomicLong, long j) {
|
|
Subscription subscription = atomicReference.get();
|
|
if (subscription != null) {
|
|
subscription.request(j);
|
|
return;
|
|
}
|
|
if (validate(j)) {
|
|
BackpressureHelper.add(atomicLong, j);
|
|
Subscription subscription2 = atomicReference.get();
|
|
if (subscription2 != null) {
|
|
long andSet = atomicLong.getAndSet(0L);
|
|
if (andSet != 0) {
|
|
subscription2.request(andSet);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public static boolean deferredSetOnce(AtomicReference<Subscription> atomicReference, AtomicLong atomicLong, Subscription subscription) {
|
|
if (!setOnce(atomicReference, subscription)) {
|
|
return false;
|
|
}
|
|
long andSet = atomicLong.getAndSet(0L);
|
|
if (andSet == 0) {
|
|
return true;
|
|
}
|
|
subscription.request(andSet);
|
|
return true;
|
|
}
|
|
|
|
public static boolean replace(AtomicReference<Subscription> atomicReference, Subscription subscription) {
|
|
while (true) {
|
|
Subscription subscription2 = atomicReference.get();
|
|
if (subscription2 == CANCELLED) {
|
|
if (subscription == null) {
|
|
return false;
|
|
}
|
|
subscription.cancel();
|
|
return false;
|
|
}
|
|
while (!atomicReference.compareAndSet(subscription2, subscription)) {
|
|
if (atomicReference.get() != subscription2) {
|
|
break;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public static void reportMoreProduced(long j) {
|
|
RxJavaPlugins.onError(new ProtocolViolationException(ArcMode$$ExternalSyntheticOutline0.m(j, "More produced than requested: ")));
|
|
}
|
|
|
|
public static void reportSubscriptionSet() {
|
|
RxJavaPlugins.onError(new ProtocolViolationException("Subscription already set!"));
|
|
}
|
|
|
|
public static boolean set(AtomicReference<Subscription> atomicReference, Subscription subscription) {
|
|
while (true) {
|
|
Subscription subscription2 = atomicReference.get();
|
|
if (subscription2 == CANCELLED) {
|
|
if (subscription == null) {
|
|
return false;
|
|
}
|
|
subscription.cancel();
|
|
return false;
|
|
}
|
|
while (!atomicReference.compareAndSet(subscription2, subscription)) {
|
|
if (atomicReference.get() != subscription2) {
|
|
break;
|
|
}
|
|
}
|
|
if (subscription2 == null) {
|
|
return true;
|
|
}
|
|
subscription2.cancel();
|
|
return true;
|
|
}
|
|
}
|
|
|
|
public static boolean setOnce(AtomicReference<Subscription> atomicReference, Subscription subscription) {
|
|
Objects.requireNonNull(subscription, "s is null");
|
|
while (!atomicReference.compareAndSet(null, subscription)) {
|
|
if (atomicReference.get() != null) {
|
|
subscription.cancel();
|
|
if (atomicReference.get() == CANCELLED) {
|
|
return false;
|
|
}
|
|
reportSubscriptionSet();
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public static boolean validate(Subscription subscription, Subscription subscription2) {
|
|
if (subscription2 == null) {
|
|
RxJavaPlugins.onError(new NullPointerException("next is null"));
|
|
return false;
|
|
}
|
|
if (subscription == null) {
|
|
return true;
|
|
}
|
|
subscription2.cancel();
|
|
reportSubscriptionSet();
|
|
return false;
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscription
|
|
public void request(long j) {
|
|
}
|
|
|
|
public static boolean validate(long j) {
|
|
if (j > 0) {
|
|
return true;
|
|
}
|
|
RxJavaPlugins.onError(new IllegalArgumentException(ArcMode$$ExternalSyntheticOutline0.m(j, "n > 0 required but it was ")));
|
|
return false;
|
|
}
|
|
|
|
@Override // org.reactivestreams.Subscription
|
|
public void cancel() {
|
|
}
|
|
|
|
public static boolean setOnce(AtomicReference<Subscription> atomicReference, Subscription subscription, long j) {
|
|
if (!setOnce(atomicReference, subscription)) {
|
|
return false;
|
|
}
|
|
subscription.request(j);
|
|
return true;
|
|
}
|
|
}
|