package x7;

import java.util.concurrent.atomic.AtomicReference;

/* JADX INFO: loaded from: classes.dex */
public abstract class D {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final C f18734a = new C(new byte[0], 0, 0, false);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final int f18735b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final AtomicReference[] f18736c;

    static {
        int iHighestOneBit = Integer.highestOneBit((Runtime.getRuntime().availableProcessors() * 2) - 1);
        f18735b = iHighestOneBit;
        AtomicReference[] atomicReferenceArr = new AtomicReference[iHighestOneBit];
        for (int i = 0; i < iHighestOneBit; i++) {
            atomicReferenceArr[i] = new AtomicReference();
        }
        f18736c = atomicReferenceArr;
    }

    public static final void a(C c3) {
        P6.g.e(c3, "segment");
        if (c3.f18732f != null || c3.f18733g != null) {
            throw new IllegalArgumentException("Failed requirement.");
        }
        if (c3.f18730d) {
            return;
        }
        AtomicReference atomicReference = f18736c[(int) (Thread.currentThread().getId() & (((long) f18735b) - 1))];
        C c8 = f18734a;
        C c9 = (C) atomicReference.getAndSet(c8);
        if (c9 == c8) {
            return;
        }
        int i = c9 != null ? c9.f18729c : 0;
        if (i >= 65536) {
            atomicReference.set(c9);
            return;
        }
        c3.f18732f = c9;
        c3.f18728b = 0;
        c3.f18729c = i + 8192;
        atomicReference.set(c3);
    }

    public static final C b() {
        AtomicReference atomicReference = f18736c[(int) (Thread.currentThread().getId() & (((long) f18735b) - 1))];
        C c3 = f18734a;
        C c8 = (C) atomicReference.getAndSet(c3);
        if (c8 == c3) {
            return new C();
        }
        if (c8 == null) {
            atomicReference.set(null);
            return new C();
        }
        atomicReference.set(c8.f18732f);
        c8.f18732f = null;
        c8.f18729c = 0;
        return c8;
    }
}
