Rabbit-R1/android (non root)/java/sources/com/google/common/hash/LongAdder.java

120 lines
3.1 KiB
Java
Raw Normal View History

2024-05-21 16:08:36 -05:00
package com.google.common.hash;
import com.google.common.hash.Striped64;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
@ElementTypesAreNonnullByDefault
/* loaded from: classes3.dex */
final class LongAdder extends Striped64 implements Serializable, LongAddable {
private static final long serialVersionUID = 7249069246863182397L;
@Override // com.google.common.hash.Striped64
final long fn(long j, long j2) {
return j + j2;
}
@Override // com.google.common.hash.LongAddable
public void add(long j) {
int length;
Striped64.Cell cell;
Striped64.Cell[] cellArr = this.cells;
if (cellArr == null) {
long j2 = this.base;
if (casBase(j2, j2 + j)) {
return;
}
}
int[] iArr = threadHashCode.get();
boolean z = true;
if (iArr != null && cellArr != null && (length = cellArr.length) >= 1 && (cell = cellArr[(length - 1) & iArr[0]]) != null) {
long j3 = cell.value;
z = cell.cas(j3, j3 + j);
if (z) {
return;
}
}
retryUpdate(j, iArr, z);
}
@Override // com.google.common.hash.LongAddable
public void increment() {
add(1L);
}
public void decrement() {
add(-1L);
}
@Override // com.google.common.hash.LongAddable
public long sum() {
long j = this.base;
Striped64.Cell[] cellArr = this.cells;
if (cellArr != null) {
for (Striped64.Cell cell : cellArr) {
if (cell != null) {
j += cell.value;
}
}
}
return j;
}
public void reset() {
internalReset(0L);
}
public long sumThenReset() {
long j = this.base;
Striped64.Cell[] cellArr = this.cells;
this.base = 0L;
if (cellArr != null) {
for (Striped64.Cell cell : cellArr) {
if (cell != null) {
j += cell.value;
cell.value = 0L;
}
}
}
return j;
}
public String toString() {
return Long.toString(sum());
}
@Override // java.lang.Number
public long longValue() {
return sum();
}
@Override // java.lang.Number
public int intValue() {
return (int) sum();
}
@Override // java.lang.Number
public float floatValue() {
return (float) sum();
}
@Override // java.lang.Number
public double doubleValue() {
return sum();
}
private void writeObject(ObjectOutputStream objectOutputStream) throws IOException {
objectOutputStream.defaultWriteObject();
objectOutputStream.writeLong(sum());
}
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
objectInputStream.defaultReadObject();
this.busy = 0;
this.cells = null;
this.base = objectInputStream.readLong();
}
}