package kr;

import com.google.firebase.crashlytics.internal.metadata.UserMetadata;
import java.util.concurrent.atomic.AtomicReference;

/* loaded from: classes4.dex */
public final class w {

    /* renamed from: a, reason: collision with root package name */
    public static final w f26692a = new w();

    /* renamed from: b, reason: collision with root package name */
    private static final int f26693b = 65536;

    /* renamed from: c, reason: collision with root package name */
    private static final v f26694c = new v(new byte[0], 0, 0, false, false);

    /* renamed from: d, reason: collision with root package name */
    private static final int f26695d;

    /* renamed from: e, reason: collision with root package name */
    private static final AtomicReference[] f26696e;

    static {
        int highestOneBit = Integer.highestOneBit((Runtime.getRuntime().availableProcessors() * 2) - 1);
        f26695d = highestOneBit;
        AtomicReference[] atomicReferenceArr = new AtomicReference[highestOneBit];
        for (int i10 = 0; i10 < highestOneBit; i10++) {
            atomicReferenceArr[i10] = new AtomicReference();
        }
        f26696e = atomicReferenceArr;
    }

    private w() {
    }

    private final AtomicReference a() {
        return f26696e[(int) (Thread.currentThread().getId() & (f26695d - 1))];
    }

    public static final void b(v segment) {
        kotlin.jvm.internal.t.g(segment, "segment");
        if (!(segment.f26690f == null && segment.f26691g == null)) {
            throw new IllegalArgumentException("Failed requirement.".toString());
        }
        if (segment.f26688d) {
            return;
        }
        AtomicReference a10 = f26692a.a();
        v vVar = f26694c;
        v vVar2 = (v) a10.getAndSet(vVar);
        if (vVar2 == vVar) {
            return;
        }
        int i10 = vVar2 != null ? vVar2.f26687c : 0;
        if (i10 >= f26693b) {
            a10.set(vVar2);
            return;
        }
        segment.f26690f = vVar2;
        segment.f26686b = 0;
        segment.f26687c = i10 + UserMetadata.MAX_INTERNAL_KEY_SIZE;
        a10.set(segment);
    }

    public static final v c() {
        AtomicReference a10 = f26692a.a();
        v vVar = f26694c;
        v vVar2 = (v) a10.getAndSet(vVar);
        if (vVar2 == vVar) {
            return new v();
        }
        if (vVar2 == null) {
            a10.set(null);
            return new v();
        }
        a10.set(vVar2.f26690f);
        vVar2.f26690f = null;
        vVar2.f26687c = 0;
        return vVar2;
    }
}
