package j0.l.e.n; import c.q.a.k.a; import java.util.Iterator; import java.util.Objects; import sun.misc.Unsafe; /* compiled from: SpscUnboundedArrayQueue */ public class t extends v { public static final int o = Integer.getInteger("jctools.spsc.max.lookahead.step", 4096).intValue(); public static final long p; public static final long q; public static final long r; /* renamed from: s reason: collision with root package name */ public static final int f2844s; public static final Object t = new Object(); static { Unsafe unsafe = y.a; int arrayIndexScale = unsafe.arrayIndexScale(Object[].class); if (4 == arrayIndexScale) { f2844s = 2; } else if (8 == arrayIndexScale) { f2844s = 3; } else { throw new IllegalStateException("Unknown pointer size"); } r = (long) unsafe.arrayBaseOffset(Object[].class); try { p = unsafe.objectFieldOffset(x.class.getDeclaredField("producerIndex")); try { q = unsafe.objectFieldOffset(v.class.getDeclaredField("consumerIndex")); } catch (NoSuchFieldException e) { InternalError internalError = new InternalError(); internalError.initCause(e); throw internalError; } } catch (NoSuchFieldException e2) { InternalError internalError2 = new InternalError(); internalError2.initCause(e2); throw internalError2; } } public t(int i) { int M = a.M(i); long j = (long) (M - 1); E[] eArr = (E[]) new Object[(M + 1)]; this.l = eArr; this.k = j; this.i = Math.min(M / 4, o); this.n = eArr; this.m = j; this.j = j - 1; k(0); } public static long c(long j) { return r + (j << f2844s); } public static long d(long j, long j2) { return c(j & j2); } public static Object g(E[] eArr, long j) { return y.a.getObjectVolatile(eArr, j); } public static void j(Object[] objArr, long j, Object obj) { y.a.putOrderedObject(objArr, j, obj); } public final long e() { return y.a.getLongVolatile(this, q); } public final long h() { return y.a.getLongVolatile(this, p); } public final void i(long j) { y.a.putOrderedLong(this, q, j); } public final Iterator iterator() { throw new UnsupportedOperationException(); } public final void k(long j) { y.a.putOrderedLong(this, p, j); } public final boolean l(E[] eArr, E e, long j, long j2) { j(eArr, j2, e); k(j + 1); return true; } public final boolean offer(E e) { Objects.requireNonNull(e, "Null is not a valid element"); E[] eArr = this.l; long j = this.producerIndex; long j2 = this.k; long d = d(j, j2); if (j < this.j) { l(eArr, e, j, d); return true; } long j3 = ((long) this.i) + j; if (g(eArr, d(j3, j2)) == null) { this.j = j3 - 1; l(eArr, e, j, d); return true; } long j4 = j + 1; if (g(eArr, d(j4, j2)) != null) { l(eArr, e, j, d); return true; } E[] eArr2 = (E[]) new Object[eArr.length]; this.l = eArr2; this.j = (j2 + j) - 1; j(eArr2, d, e); j(eArr, c((long) (eArr.length - 1)), eArr2); j(eArr, d, t); k(j4); return true; } public final E peek() { E[] eArr = this.n; long j = this.consumerIndex; long j2 = this.m; E e = (E) g(eArr, d(j, j2)); if (e != t) { return e; } E[] eArr2 = (E[]) ((Object[]) g(eArr, c((long) (eArr.length - 1)))); this.n = eArr2; return (E) g(eArr2, d(j, j2)); } public final E poll() { E[] eArr = this.n; long j = this.consumerIndex; long j2 = this.m; long d = d(j, j2); E e = (E) g(eArr, d); boolean z2 = e == t; if (e != null && !z2) { j(eArr, d, null); i(j + 1); return e; } else if (!z2) { return null; } else { E[] eArr2 = (E[]) ((Object[]) g(eArr, c((long) (eArr.length - 1)))); this.n = eArr2; long d2 = d(j, j2); E e2 = (E) g(eArr2, d2); if (e2 == null) { return null; } j(eArr2, d2, null); i(j + 1); return e2; } } public final int size() { long e = e(); while (true) { long h = h(); long e2 = e(); if (e == e2) { return (int) (h - e2); } e = e2; } } }