package 㴹.K.Ԕ.㴹;

import androidx.recyclerview.widget.RecyclerView;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReferenceArray;
import ඓ.ⁱ.K.ඓ.C1252;
import 㴹.K.Ԕ.ʬ.AbstractC2435;

/* renamed from: 㴹.K.Ԕ.㴹.K  reason: contains not printable characters */
/* compiled from: SpscLinkedArrayQueue */
public final class C2487<T> implements AbstractC2435<T> {

    /* renamed from: ᕣ  reason: contains not printable characters */
    public static final Object f8477 = new Object();

    /* renamed from: 㳳  reason: contains not printable characters */
    public static final int f8478 = Integer.getInteger("jctools.spsc.max.lookahead.step", (int) RecyclerView.AbstractC0269.FLAG_APPEARED_IN_PRE_LAYOUT).intValue();

    /* renamed from: ʬ  reason: contains not printable characters */
    public int f8479;

    /* renamed from: ඓ  reason: contains not printable characters */
    public final int f8480;

    /* renamed from: ᨨ  reason: contains not printable characters */
    public final AtomicLong f8481 = new AtomicLong();

    /* renamed from: ῲ  reason: contains not printable characters */
    public final AtomicLong f8482 = new AtomicLong();

    /* renamed from: ⁱ  reason: contains not printable characters */
    public final int f8483;

    /* renamed from: 㴹  reason: contains not printable characters */
    public AtomicReferenceArray<Object> f8484;

    /* renamed from: 㸾  reason: contains not printable characters */
    public long f8485;

    /* renamed from: 㿎  reason: contains not printable characters */
    public AtomicReferenceArray<Object> f8486;

    public C2487(int i) {
        int r4 = C1252.m3334(Math.max(8, i));
        int i2 = r4 - 1;
        AtomicReferenceArray<Object> atomicReferenceArray = new AtomicReferenceArray<>(r4 + 1);
        this.f8484 = atomicReferenceArray;
        this.f8480 = i2;
        this.f8479 = Math.min(r4 / 4, f8478);
        this.f8486 = atomicReferenceArray;
        this.f8483 = i2;
        this.f8485 = (long) (i2 - 1);
        this.f8482.lazySet(0);
    }

    @Override // 㴹.K.Ԕ.ʬ.AbstractC2439
    public void clear() {
        while (true) {
            if (poll() == null && isEmpty()) {
                return;
            }
        }
    }

    @Override // 㴹.K.Ԕ.ʬ.AbstractC2439
    public boolean isEmpty() {
        return this.f8482.get() == this.f8481.get();
    }

    @Override // 㴹.K.Ԕ.ʬ.AbstractC2439
    public boolean offer(T t) {
        if (t != null) {
            AtomicReferenceArray<Object> atomicReferenceArray = this.f8484;
            long j = this.f8482.get();
            int i = this.f8480;
            int i2 = ((int) j) & i;
            if (j < this.f8485) {
                atomicReferenceArray.lazySet(i2, t);
                this.f8482.lazySet(j + 1);
                return true;
            }
            long j2 = ((long) this.f8479) + j;
            if (atomicReferenceArray.get(((int) j2) & i) == null) {
                this.f8485 = j2 - 1;
                atomicReferenceArray.lazySet(i2, t);
                this.f8482.lazySet(j + 1);
                return true;
            }
            long j3 = j + 1;
            if (atomicReferenceArray.get(((int) j3) & i) == null) {
                atomicReferenceArray.lazySet(i2, t);
                this.f8482.lazySet(j3);
                return true;
            }
            AtomicReferenceArray<Object> atomicReferenceArray2 = new AtomicReferenceArray<>(atomicReferenceArray.length());
            this.f8484 = atomicReferenceArray2;
            this.f8485 = (((long) i) + j) - 1;
            atomicReferenceArray2.lazySet(i2, t);
            atomicReferenceArray.lazySet(atomicReferenceArray.length() - 1, atomicReferenceArray2);
            atomicReferenceArray.lazySet(i2, f8477);
            this.f8482.lazySet(j3);
            return true;
        }
        throw new NullPointerException("Null is not a valid element");
    }

    @Override // 㴹.K.Ԕ.ʬ.AbstractC2435, 㴹.K.Ԕ.ʬ.AbstractC2439
    public T poll() {
        AtomicReferenceArray<Object> atomicReferenceArray = this.f8486;
        long j = this.f8481.get();
        int i = this.f8483 & ((int) j);
        T t = (T) atomicReferenceArray.get(i);
        boolean z = t == f8477;
        if (t != null && !z) {
            atomicReferenceArray.lazySet(i, null);
            this.f8481.lazySet(j + 1);
            return t;
        } else if (!z) {
            return null;
        } else {
            AtomicReferenceArray<Object> atomicReferenceArray2 = (AtomicReferenceArray) atomicReferenceArray.get(atomicReferenceArray.length() - 1);
            this.f8486 = atomicReferenceArray2;
            T t2 = (T) atomicReferenceArray2.get(i);
            if (t2 != null) {
                atomicReferenceArray2.lazySet(i, null);
                this.f8481.lazySet(j + 1);
            }
            return t2;
        }
    }
}
