package p5;

import java.util.concurrent.atomic.AtomicReference;

/* JADX INFO: loaded from: classes3.dex */
public abstract class L {

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

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

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

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

    public static final void a(K segment) {
        kotlin.jvm.internal.o.h(segment, "segment");
        if (segment.f23066f != null || segment.f23067g != null) {
            throw new IllegalArgumentException("Failed requirement.");
        }
        if (segment.f23064d) {
            return;
        }
        AtomicReference atomicReference = f23070c[(int) (Thread.currentThread().getId() & (((long) f23069b) - 1))];
        K k6 = f23068a;
        K k7 = (K) atomicReference.getAndSet(k6);
        if (k7 == k6) {
            return;
        }
        int i6 = k7 != null ? k7.f23063c : 0;
        if (i6 >= 65536) {
            atomicReference.set(k7);
            return;
        }
        segment.f23066f = k7;
        segment.f23062b = 0;
        segment.f23063c = i6 + 8192;
        atomicReference.set(segment);
    }

    public static final K b() {
        AtomicReference atomicReference = f23070c[(int) (Thread.currentThread().getId() & (((long) f23069b) - 1))];
        K k6 = f23068a;
        K k7 = (K) atomicReference.getAndSet(k6);
        if (k7 == k6) {
            return new K();
        }
        if (k7 == null) {
            atomicReference.set(null);
            return new K();
        }
        atomicReference.set(k7.f23066f);
        k7.f23066f = null;
        k7.f23063c = 0;
        return k7;
    }
}
