mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-24 16:12:29 -06:00
90 lines
4.1 KiB
Java
90 lines
4.1 KiB
Java
package okio;
|
|
|
|
import java.util.concurrent.atomic.AtomicReference;
|
|
import kotlin.Metadata;
|
|
import kotlin.jvm.JvmStatic;
|
|
import kotlin.jvm.internal.Intrinsics;
|
|
|
|
/* compiled from: SegmentPool.kt */
|
|
@Metadata(bv = {1, 0, 3}, 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, 4, 0})
|
|
/* loaded from: classes3.dex */
|
|
public final class SegmentPool {
|
|
private static final int HASH_BUCKET_COUNT;
|
|
private static final AtomicReference<Segment>[] hashBuckets;
|
|
public static final SegmentPool INSTANCE = new SegmentPool();
|
|
private static final int MAX_SIZE = 65536;
|
|
private static final Segment LOCK = new Segment(new byte[0], 0, 0, false, false);
|
|
|
|
public final int getMAX_SIZE() {
|
|
return MAX_SIZE;
|
|
}
|
|
|
|
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() {
|
|
}
|
|
|
|
public final int getByteCount() {
|
|
Segment segment = firstRef().get();
|
|
if (segment != null) {
|
|
return segment.limit;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
@JvmStatic
|
|
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;
|
|
}
|
|
|
|
@JvmStatic
|
|
public static final void recycle(Segment segment) {
|
|
AtomicReference<Segment> firstRef;
|
|
Segment segment2;
|
|
Intrinsics.checkNotNullParameter(segment, "segment");
|
|
if (!(segment.next == null && segment.prev == null)) {
|
|
throw new IllegalArgumentException("Failed requirement.".toString());
|
|
}
|
|
if (segment.shared || (segment2 = (firstRef = INSTANCE.firstRef()).get()) == LOCK) {
|
|
return;
|
|
}
|
|
int i = segment2 != null ? segment2.limit : 0;
|
|
if (i >= MAX_SIZE) {
|
|
return;
|
|
}
|
|
segment.next = segment2;
|
|
segment.pos = 0;
|
|
segment.limit = i + 8192;
|
|
if (firstRef.compareAndSet(segment2, segment)) {
|
|
return;
|
|
}
|
|
segment.next = null;
|
|
}
|
|
|
|
private final AtomicReference<Segment> firstRef() {
|
|
Thread currentThread = Thread.currentThread();
|
|
Intrinsics.checkNotNullExpressionValue(currentThread, "Thread.currentThread()");
|
|
return hashBuckets[(int) (currentThread.getId() & (HASH_BUCKET_COUNT - 1))];
|
|
}
|
|
}
|