package d.a.s.f;

import a.a.a.a.c.n0;
import d.a.s.c.c;
import java.util.Objects;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReferenceArray;

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final Integer f5815b = Integer.getInteger("jctools.spsc.max.lookahead.step", 4096);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final int f5816c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final AtomicLong f5817d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public long f5818e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final AtomicLong f5819f;

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

    public a(int i2) {
        super(n0.s(i2));
        this.f5816c = length() - 1;
        this.f5817d = new AtomicLong();
        this.f5819f = new AtomicLong();
        this.f5820g = Math.min(i2 / 4, f5815b.intValue());
    }

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

    @Override // d.a.s.c.d
    public boolean isEmpty() {
        return this.f5817d.get() == this.f5819f.get();
    }

    @Override // d.a.s.c.d
    public boolean offer(E e2) {
        Objects.requireNonNull(e2, "Null is not a valid element");
        int i2 = this.f5816c;
        long j2 = this.f5817d.get();
        int i3 = ((int) j2) & i2;
        if (j2 >= this.f5818e) {
            long j3 = ((long) this.f5820g) + j2;
            if (get(i2 & ((int) j3)) == null) {
                this.f5818e = j3;
            } else if (get(i3) != null) {
                return false;
            }
        }
        lazySet(i3, e2);
        this.f5817d.lazySet(j2 + 1);
        return true;
    }

    @Override // d.a.s.c.c, d.a.s.c.d
    public E poll() {
        long j2 = this.f5819f.get();
        int i2 = ((int) j2) & this.f5816c;
        E e2 = get(i2);
        if (e2 == null) {
            return null;
        }
        this.f5819f.lazySet(j2 + 1);
        lazySet(i2, null);
        return e2;
    }
}
