mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-15 02:17:18 +01:00
92 lines
2.8 KiB
Java
92 lines
2.8 KiB
Java
package io.reactivex.rxjava3.internal.util;
|
|
|
|
import androidx.compose.animation.core.ArcMode$$ExternalSyntheticOutline0;
|
|
import io.reactivex.rxjava3.annotations.NonNull;
|
|
import io.reactivex.rxjava3.plugins.RxJavaPlugins;
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
/* loaded from: classes10.dex */
|
|
public final class BackpressureHelper {
|
|
private BackpressureHelper() {
|
|
throw new IllegalStateException("No instances!");
|
|
}
|
|
|
|
public static long add(@NonNull AtomicLong atomicLong, long j) {
|
|
long j2;
|
|
do {
|
|
j2 = atomicLong.get();
|
|
if (j2 == Long.MAX_VALUE) {
|
|
return Long.MAX_VALUE;
|
|
}
|
|
} while (!atomicLong.compareAndSet(j2, addCap(j2, j)));
|
|
return j2;
|
|
}
|
|
|
|
public static long addCancel(@NonNull AtomicLong atomicLong, long j) {
|
|
long j2;
|
|
do {
|
|
j2 = atomicLong.get();
|
|
if (j2 == Long.MIN_VALUE) {
|
|
return Long.MIN_VALUE;
|
|
}
|
|
if (j2 == Long.MAX_VALUE) {
|
|
return Long.MAX_VALUE;
|
|
}
|
|
} while (!atomicLong.compareAndSet(j2, addCap(j2, j)));
|
|
return j2;
|
|
}
|
|
|
|
public static long addCap(long j, long j2) {
|
|
long j3 = j + j2;
|
|
if (j3 < 0) {
|
|
return Long.MAX_VALUE;
|
|
}
|
|
return j3;
|
|
}
|
|
|
|
public static long multiplyCap(long j, long j2) {
|
|
long j3 = j * j2;
|
|
if (((j | j2) >>> 31) == 0 || j3 / j == j2) {
|
|
return j3;
|
|
}
|
|
return Long.MAX_VALUE;
|
|
}
|
|
|
|
public static long produced(@NonNull AtomicLong atomicLong, long j) {
|
|
long j2;
|
|
long j3;
|
|
do {
|
|
j2 = atomicLong.get();
|
|
if (j2 == Long.MAX_VALUE) {
|
|
return Long.MAX_VALUE;
|
|
}
|
|
j3 = j2 - j;
|
|
if (j3 < 0) {
|
|
RxJavaPlugins.onError(new IllegalStateException(ArcMode$$ExternalSyntheticOutline0.m(j3, "More produced than requested: ")));
|
|
j3 = 0;
|
|
}
|
|
} while (!atomicLong.compareAndSet(j2, j3));
|
|
return j3;
|
|
}
|
|
|
|
public static long producedCancel(@NonNull AtomicLong atomicLong, long j) {
|
|
long j2;
|
|
long j3;
|
|
do {
|
|
j2 = atomicLong.get();
|
|
if (j2 == Long.MIN_VALUE) {
|
|
return Long.MIN_VALUE;
|
|
}
|
|
if (j2 == Long.MAX_VALUE) {
|
|
return Long.MAX_VALUE;
|
|
}
|
|
j3 = j2 - j;
|
|
if (j3 < 0) {
|
|
RxJavaPlugins.onError(new IllegalStateException(ArcMode$$ExternalSyntheticOutline0.m(j3, "More produced than requested: ")));
|
|
j3 = 0;
|
|
}
|
|
} while (!atomicLong.compareAndSet(j2, j3));
|
|
return j3;
|
|
}
|
|
}
|