package i.a.n.f;

import i.a.n.c.d;
import i.a.n.h.f;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReferenceArray;

/* JADX INFO: compiled from: SpscArrayQueue.java */
/* JADX INFO: loaded from: classes.dex */
public final class a<E> extends AtomicReferenceArray<E> implements d<E> {

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private static final Integer f859h = Integer.getInteger("jctools.spsc.max.lookahead.step", 4096);
    final int b;
    final AtomicLong d;
    long e;
    final AtomicLong f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    final int f860g;

    public a(int i2) {
        super(f.a(i2));
        this.b = length() - 1;
        this.d = new AtomicLong();
        this.f = new AtomicLong();
        this.f860g = Math.min(i2 / 4, f859h.intValue());
    }

    int a(long j2) {
        return ((int) j2) & this.b;
    }

    int b(long j2, int i2) {
        return ((int) j2) & i2;
    }

    E c(int i2) {
        return get(i2);
    }

    @Override // i.a.n.c.e
    public void clear() {
        while (true) {
            if (poll() == null && isEmpty()) {
                return;
            }
        }
    }

    void d(long j2) {
        this.f.lazySet(j2);
    }

    void e(int i2, E e) {
        lazySet(i2, e);
    }

    void f(long j2) {
        this.d.lazySet(j2);
    }

    @Override // i.a.n.c.e
    public boolean isEmpty() {
        return this.d.get() == this.f.get();
    }

    @Override // i.a.n.c.e
    public boolean offer(E e) {
        if (e == null) {
            throw new NullPointerException("Null is not a valid element");
        }
        int i2 = this.b;
        long j2 = this.d.get();
        int iB = b(j2, i2);
        if (j2 >= this.e) {
            long j3 = ((long) this.f860g) + j2;
            if (c(b(j3, i2)) == null) {
                this.e = j3;
            } else if (c(iB) != null) {
                return false;
            }
        }
        e(iB, e);
        f(j2 + 1);
        return true;
    }

    @Override // i.a.n.c.d, i.a.n.c.e
    public E poll() {
        long j2 = this.f.get();
        int iA = a(j2);
        E eC = c(iA);
        if (eC == null) {
            return null;
        }
        d(j2 + 1);
        e(iA, null);
        return eC;
    }
}
