package v0;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

/* JADX INFO: renamed from: v0.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public class C0729a implements b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private volatile int f6658a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private volatile int f6659b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private volatile double[] f6660c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private int f6661d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private int f6662e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    private boolean f6663f = true;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    private boolean f6664g = true;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    private volatile boolean f6665h = true;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    final Lock f6666i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    final Condition f6667j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    final Condition f6668k;

    public C0729a() {
        ReentrantLock reentrantLock = new ReentrantLock();
        this.f6666i = reentrantLock;
        this.f6667j = reentrantLock.newCondition();
        this.f6668k = reentrantLock.newCondition();
    }

    public static boolean e(int i2) {
        return (i2 & (i2 + (-1))) == 0;
    }

    private double h() {
        double d2 = this.f6660c[this.f6658a & this.f6661d];
        this.f6658a = (this.f6658a + 1) & this.f6662e;
        return d2;
    }

    private void k(double d2) {
        this.f6660c[this.f6659b & this.f6661d] = d2;
        this.f6659b = (this.f6659b + 1) & this.f6662e;
    }

    @Override // v0.b
    public void a(double[] dArr, int i2, int i3) {
        for (int i4 = 0; i4 < i3; i4++) {
            b(dArr[i4 + i2]);
        }
    }

    @Override // v0.b
    public void b(double d2) {
        if (this.f6663f) {
            this.f6666i.lock();
            while (this.f6665h && d() == this.f6660c.length) {
                try {
                    try {
                        this.f6667j.await();
                    } catch (InterruptedException unused) {
                        return;
                    }
                } finally {
                    this.f6666i.unlock();
                }
            }
            if (this.f6665h) {
                k(d2);
            }
        } else if (d() != this.f6660c.length) {
            k(d2);
        }
        if (this.f6664g) {
            this.f6666i.lock();
            this.f6668k.signal();
        }
    }

    public void c(int i2) {
        if (!e(i2)) {
            throw new IllegalArgumentException("Size must be a power of two.");
        }
        this.f6660c = new double[i2];
        this.f6661d = i2 - 1;
        this.f6662e = (i2 * 2) - 1;
    }

    public int d() {
        return (this.f6659b - this.f6658a) & this.f6662e;
    }

    public double f() {
        if (this.f6664g) {
            this.f6666i.lock();
            while (this.f6665h && d() < 1) {
                try {
                    try {
                        this.f6668k.await();
                    } catch (InterruptedException unused) {
                        return Double.NaN;
                    }
                } finally {
                    this.f6666i.unlock();
                }
            }
            dH = this.f6665h ? h() : Double.NaN;
        } else if (this.f6665h && this.f6658a != this.f6659b) {
            dH = h();
        }
        if (this.f6663f) {
            this.f6666i.lock();
            this.f6667j.signal();
        }
        return dH;
    }

    public int g(double[] dArr, int i2, int i3) {
        if (!this.f6665h) {
            return 0;
        }
        if (!this.f6664g) {
            i3 = Math.min(d(), i3);
        }
        int i4 = 0;
        for (int i5 = 0; this.f6665h && i5 < i3; i5++) {
            double dF = f();
            if (Double.isNaN(dF)) {
                break;
            }
            dArr[i5 + i2] = dF;
            i4++;
        }
        return i4;
    }

    public void i(boolean z2) {
        this.f6664g = z2;
    }

    public void j(boolean z2) {
        this.f6663f = z2;
    }
}
