mirror of
https://github.com/VibedByKaKi/alexandroid.git
synced 2026-11-15 18:37:17 +01:00
96 lines
4.2 KiB
Java
96 lines
4.2 KiB
Java
package okio;
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import kotlin.Metadata;
|
|
import kotlin.jvm.JvmStatic;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import rx.Single$$ExternalSyntheticBUOutline0;
|
|
|
|
/* compiled from: r8-map-id-b9432e0f623b4a4bff4ba50a8a24c4aafad2c1e11092747b9fb5e6a22af5a940 */
|
|
@Metadata(d1 = {"\u0000.\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0006\n\u0002\u0010\u0011\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u0002\n\u0002\b\u0003\bÀ\u0002\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\u0010\u0010\u0010\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\u00060\u000eH\u0002J\u0010\u0010\u0011\u001a\u00020\u00122\u0006\u0010\u0013\u001a\u00020\u0006H\u0007J\b\u0010\u0014\u001a\u00020\u0006H\u0007R\u000e\u0010\u0003\u001a\u00020\u0004X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0006X\u0082\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\u0007\u001a\u00020\u0004X\u0086D¢\u0006\b\n\u0000\u001a\u0004\b\b\u0010\tR\u0011\u0010\n\u001a\u00020\u00048F¢\u0006\u0006\u001a\u0004\b\u000b\u0010\tR\u001e\u0010\f\u001a\u0010\u0012\f\u0012\n\u0012\u0006\u0012\u0004\u0018\u00010\u00060\u000e0\rX\u0082\u0004¢\u0006\u0004\n\u0002\u0010\u000f¨\u0006\u0015"}, d2 = {"Lokio/SegmentPool;", "", "()V", "HASH_BUCKET_COUNT", "", "LOCK", "Lokio/Segment;", "MAX_SIZE", "getMAX_SIZE", "()I", "byteCount", "getByteCount", "hashBuckets", "", "Ljava/util/concurrent/atomic/AtomicReference;", "[Ljava/util/concurrent/atomic/AtomicReference;", "firstRef", "recycle", "", "segment", "take", "okio"}, k = 1, mv = {1, 9, 0}, xi = 48)
|
|
/* loaded from: classes10.dex */
|
|
public final class SegmentPool {
|
|
private static final int HASH_BUCKET_COUNT;
|
|
|
|
@NotNull
|
|
private static final AtomicReference<Segment>[] hashBuckets;
|
|
|
|
@NotNull
|
|
public static final SegmentPool INSTANCE = new SegmentPool();
|
|
private static final int MAX_SIZE = 65536;
|
|
|
|
@NotNull
|
|
private static final Segment LOCK = new Segment(new byte[0], 0, 0, false, false);
|
|
|
|
static {
|
|
int highestOneBit = Integer.highestOneBit((Runtime.getRuntime().availableProcessors() * 2) - 1);
|
|
HASH_BUCKET_COUNT = highestOneBit;
|
|
AtomicReference<Segment>[] atomicReferenceArr = new AtomicReference[highestOneBit];
|
|
for (int i = 0; i < highestOneBit; i++) {
|
|
atomicReferenceArr[i] = new AtomicReference<>();
|
|
}
|
|
hashBuckets = atomicReferenceArr;
|
|
}
|
|
|
|
private SegmentPool() {
|
|
}
|
|
|
|
private final AtomicReference<Segment> firstRef() {
|
|
return hashBuckets[(int) (Thread.currentThread().getId() & (HASH_BUCKET_COUNT - 1))];
|
|
}
|
|
|
|
@JvmStatic
|
|
public static final void recycle(@NotNull Segment segment) {
|
|
AtomicReference<Segment> firstRef;
|
|
Segment segment2;
|
|
Segment andSet;
|
|
segment.getClass();
|
|
if (segment.next != null || segment.prev != null) {
|
|
Single$$ExternalSyntheticBUOutline0.m$3("Failed requirement.");
|
|
return;
|
|
}
|
|
if (segment.shared || (andSet = (firstRef = INSTANCE.firstRef()).getAndSet((segment2 = LOCK))) == segment2) {
|
|
return;
|
|
}
|
|
int i = andSet != null ? andSet.limit : 0;
|
|
if (i >= MAX_SIZE) {
|
|
firstRef.set(andSet);
|
|
return;
|
|
}
|
|
segment.next = andSet;
|
|
segment.pos = 0;
|
|
segment.limit = i + 8192;
|
|
firstRef.set(segment);
|
|
}
|
|
|
|
@JvmStatic
|
|
@NotNull
|
|
public static final Segment take() {
|
|
AtomicReference<Segment> firstRef = INSTANCE.firstRef();
|
|
Segment segment = LOCK;
|
|
Segment andSet = firstRef.getAndSet(segment);
|
|
if (andSet == segment) {
|
|
return new Segment();
|
|
}
|
|
if (andSet == null) {
|
|
firstRef.set(null);
|
|
return new Segment();
|
|
}
|
|
firstRef.set(andSet.next);
|
|
andSet.next = null;
|
|
andSet.limit = 0;
|
|
return andSet;
|
|
}
|
|
|
|
public final int getByteCount() {
|
|
Segment segment = firstRef().get();
|
|
if (segment == null) {
|
|
return 0;
|
|
}
|
|
return segment.limit;
|
|
}
|
|
|
|
public final int getMAX_SIZE() {
|
|
return MAX_SIZE;
|
|
}
|
|
}
|