119 lines
3.1 KiB
Java
119 lines
3.1 KiB
Java
|
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;
|
||
|
|
||
|
/* loaded from: classes2.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 final 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) > 0 && (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 final void increment() {
|
||
|
add(1L);
|
||
|
}
|
||
|
|
||
|
public final void decrement() {
|
||
|
add(-1L);
|
||
|
}
|
||
|
|
||
|
@Override // com.google.common.hash.LongAddable
|
||
|
public final 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 final void reset() {
|
||
|
internalReset(0L);
|
||
|
}
|
||
|
|
||
|
public final 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 final String toString() {
|
||
|
return Long.toString(sum());
|
||
|
}
|
||
|
|
||
|
@Override // java.lang.Number
|
||
|
public final long longValue() {
|
||
|
return sum();
|
||
|
}
|
||
|
|
||
|
@Override // java.lang.Number
|
||
|
public final int intValue() {
|
||
|
return (int) sum();
|
||
|
}
|
||
|
|
||
|
@Override // java.lang.Number
|
||
|
public final float floatValue() {
|
||
|
return (float) sum();
|
||
|
}
|
||
|
|
||
|
@Override // java.lang.Number
|
||
|
public final 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();
|
||
|
}
|
||
|
}
|