44 lines
1.1 KiB
Java
44 lines
1.1 KiB
Java
package io.reactivex.internal.util;
|
|
|
|
import io.reactivex.plugins.RxJavaPlugins;
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
|
|
/* loaded from: classes2.dex */
|
|
public final class BackpressureHelper {
|
|
public static long a(long j, long j2) {
|
|
long j3 = j + j2;
|
|
if (j3 < 0) {
|
|
return Long.MAX_VALUE;
|
|
}
|
|
return j3;
|
|
}
|
|
|
|
public static long a(AtomicLong atomicLong, long j) {
|
|
long j2;
|
|
do {
|
|
j2 = atomicLong.get();
|
|
if (j2 == Long.MAX_VALUE) {
|
|
return Long.MAX_VALUE;
|
|
}
|
|
} while (!atomicLong.compareAndSet(j2, a(j2, j)));
|
|
return j2;
|
|
}
|
|
|
|
public static long b(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.b(new IllegalStateException("More produced than requested: " + j3));
|
|
j3 = 0L;
|
|
}
|
|
} while (!atomicLong.compareAndSet(j2, j3));
|
|
return j3;
|
|
}
|
|
}
|