158 lines
5.5 KiB
Java
158 lines
5.5 KiB
Java
package o;
|
|
|
|
import java.util.concurrent.atomic.AtomicLong;
|
|
import java.util.concurrent.atomic.AtomicReferenceArray;
|
|
|
|
/* renamed from: o.fZs, reason: case insensitive filesystem */
|
|
/* loaded from: classes6.dex */
|
|
public final class C13416fZs<T> implements InterfaceC13408fZk<T> {
|
|
private static int a = Integer.getInteger("jctools.spsc.max.lookahead.step", 4096).intValue();
|
|
private static final Object c = new Object();
|
|
public final AtomicLong b;
|
|
private AtomicReferenceArray<Object> d;
|
|
public final AtomicLong e;
|
|
private int f;
|
|
private int g;
|
|
private AtomicReferenceArray<Object> h;
|
|
private int i;
|
|
private long j;
|
|
|
|
public C13416fZs(int i) {
|
|
AtomicLong atomicLong = new AtomicLong();
|
|
this.b = atomicLong;
|
|
this.e = new AtomicLong();
|
|
int numberOfLeadingZeros = 1 << (32 - Integer.numberOfLeadingZeros(Math.max(8, i) - 1));
|
|
int i2 = numberOfLeadingZeros - 1;
|
|
AtomicReferenceArray<Object> atomicReferenceArray = new AtomicReferenceArray<>(numberOfLeadingZeros + 1);
|
|
this.h = atomicReferenceArray;
|
|
this.g = i2;
|
|
this.i = Math.min(numberOfLeadingZeros / 4, a);
|
|
this.d = atomicReferenceArray;
|
|
this.f = i2;
|
|
this.j = numberOfLeadingZeros - 2;
|
|
atomicLong.lazySet(0L);
|
|
}
|
|
|
|
@Override // o.InterfaceC13414fZq
|
|
public final boolean b(T t) {
|
|
if (t == null) {
|
|
throw new NullPointerException("Null is not a valid element");
|
|
}
|
|
AtomicReferenceArray<Object> atomicReferenceArray = this.h;
|
|
long j = this.b.get();
|
|
int i = this.g;
|
|
int i2 = ((int) j) & i;
|
|
if (j >= this.j) {
|
|
long j2 = this.i + j;
|
|
if (atomicReferenceArray.get(((int) j2) & i) == null) {
|
|
this.j = j2 - 1;
|
|
atomicReferenceArray.lazySet(i2, t);
|
|
this.b.lazySet(j + 1);
|
|
return true;
|
|
}
|
|
long j3 = 1 + j;
|
|
if (atomicReferenceArray.get(((int) j3) & i) != null) {
|
|
b(atomicReferenceArray, j, i2, t, i);
|
|
return true;
|
|
}
|
|
atomicReferenceArray.lazySet(i2, t);
|
|
this.b.lazySet(j3);
|
|
return true;
|
|
}
|
|
atomicReferenceArray.lazySet(i2, t);
|
|
this.b.lazySet(j + 1);
|
|
return true;
|
|
}
|
|
|
|
private void b(AtomicReferenceArray<Object> atomicReferenceArray, long j, int i, T t, long j2) {
|
|
AtomicReferenceArray<Object> atomicReferenceArray2 = new AtomicReferenceArray<>(atomicReferenceArray.length());
|
|
this.h = atomicReferenceArray2;
|
|
this.j = (j2 + j) - 1;
|
|
atomicReferenceArray2.lazySet(i, t);
|
|
atomicReferenceArray.lazySet(atomicReferenceArray.length() - 1, atomicReferenceArray2);
|
|
atomicReferenceArray.lazySet(i, c);
|
|
this.b.lazySet(j + 1);
|
|
}
|
|
|
|
@Override // o.InterfaceC13408fZk, o.InterfaceC13414fZq
|
|
public final T b() {
|
|
AtomicReferenceArray<Object> atomicReferenceArray = this.d;
|
|
long j = this.e.get();
|
|
int i = this.f;
|
|
int i2 = ((int) j) & i;
|
|
T t = (T) atomicReferenceArray.get(i2);
|
|
boolean z = t == c;
|
|
if (t != null && !z) {
|
|
atomicReferenceArray.lazySet(i2, null);
|
|
this.e.lazySet(j + 1);
|
|
return t;
|
|
}
|
|
if (!z) {
|
|
return null;
|
|
}
|
|
int i3 = i + 1;
|
|
AtomicReferenceArray<Object> atomicReferenceArray2 = (AtomicReferenceArray) atomicReferenceArray.get(i3);
|
|
atomicReferenceArray.lazySet(i3, null);
|
|
this.d = atomicReferenceArray2;
|
|
T t2 = (T) atomicReferenceArray2.get(i2);
|
|
if (t2 != null) {
|
|
atomicReferenceArray2.lazySet(i2, null);
|
|
this.e.lazySet(j + 1);
|
|
}
|
|
return t2;
|
|
}
|
|
|
|
public final T a() {
|
|
AtomicReferenceArray<Object> atomicReferenceArray = this.d;
|
|
long j = this.e.get();
|
|
int i = this.f;
|
|
int i2 = ((int) j) & i;
|
|
T t = (T) atomicReferenceArray.get(i2);
|
|
if (t != c) {
|
|
return t;
|
|
}
|
|
int i3 = i + 1;
|
|
AtomicReferenceArray<Object> atomicReferenceArray2 = (AtomicReferenceArray) atomicReferenceArray.get(i3);
|
|
atomicReferenceArray.lazySet(i3, null);
|
|
this.d = atomicReferenceArray2;
|
|
return (T) atomicReferenceArray2.get(i2);
|
|
}
|
|
|
|
@Override // o.InterfaceC13414fZq
|
|
public final void e() {
|
|
while (true) {
|
|
if (b() == null && this.b.get() == this.e.get()) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override // o.InterfaceC13414fZq
|
|
public final boolean c() {
|
|
return this.b.get() == this.e.get();
|
|
}
|
|
|
|
public final boolean e(T t, T t2) {
|
|
AtomicReferenceArray<Object> atomicReferenceArray = this.h;
|
|
long j = this.b.get();
|
|
int i = this.g;
|
|
long j2 = 2 + j;
|
|
if (atomicReferenceArray.get(((int) j2) & i) != null) {
|
|
AtomicReferenceArray<Object> atomicReferenceArray2 = new AtomicReferenceArray<>(atomicReferenceArray.length());
|
|
this.h = atomicReferenceArray2;
|
|
int i2 = ((int) j) & i;
|
|
atomicReferenceArray2.lazySet(i2 + 1, t2);
|
|
atomicReferenceArray2.lazySet(i2, t);
|
|
atomicReferenceArray.lazySet(atomicReferenceArray.length() - 1, atomicReferenceArray2);
|
|
atomicReferenceArray.lazySet(i2, c);
|
|
this.b.lazySet(j2);
|
|
} else {
|
|
int i3 = ((int) j) & i;
|
|
atomicReferenceArray.lazySet(i3 + 1, t2);
|
|
atomicReferenceArray.lazySet(i3, t);
|
|
this.b.lazySet(j2);
|
|
}
|
|
return true;
|
|
}
|
|
}
|