package okio;

import java.util.concurrent.atomic.AtomicReference;

/* JADX INFO: loaded from: classes2.dex */
public final class A {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static final int f6009c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static final AtomicReference[] f6010d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final A f6011e = new A();

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static final int f6007a = 65536;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static final y f6008b = new y(new byte[0], 0, 0, false, false);

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

    private A() {
    }

    private final AtomicReference a() {
        Thread threadCurrentThread = Thread.currentThread();
        kotlin.jvm.internal.l.d(threadCurrentThread, "Thread.currentThread()");
        return f6010d[(int) (threadCurrentThread.getId() & (((long) f6009c) - 1))];
    }

    public static final void b(y segment) {
        kotlin.jvm.internal.l.e(segment, "segment");
        if (!(segment.f6076f == null && segment.f6077g == null)) {
            throw new IllegalArgumentException("Failed requirement.");
        }
        if (segment.f6074d) {
            return;
        }
        AtomicReference atomicReferenceA = f6011e.a();
        y yVar = (y) atomicReferenceA.get();
        if (yVar == f6008b) {
            return;
        }
        int i2 = yVar != null ? yVar.f6073c : 0;
        if (i2 >= f6007a) {
            return;
        }
        segment.f6076f = yVar;
        segment.f6072b = 0;
        segment.f6073c = i2 + 8192;
        if (z.a(atomicReferenceA, yVar, segment)) {
            return;
        }
        segment.f6076f = null;
    }

    public static final y c() {
        AtomicReference atomicReferenceA = f6011e.a();
        y yVar = f6008b;
        y yVar2 = (y) atomicReferenceA.getAndSet(yVar);
        if (yVar2 == yVar) {
            return new y();
        }
        if (yVar2 == null) {
            atomicReferenceA.set(null);
            return new y();
        }
        atomicReferenceA.set(yVar2.f6076f);
        yVar2.f6076f = null;
        yVar2.f6073c = 0;
        return yVar2;
    }
}
