content: package okio;
  
  import java.util.concurrent.atomic.AtomicReference;
  import kotlin.Metadata;
  import kotlin.jvm.JvmStatic;
  import kotlin.jvm.internal.Intrinsics;
  
  @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\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0005\u001a\u00020\u0006X\u0004¢\u0006\u0002\n\u0000R\u0014\u0010\u0007\u001a\u00020\u0004XD¢\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\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})
  /* compiled from: SegmentPool.kt */
  public final class SegmentPool {
      private static final int HASH_BUCKET_COUNT;
      public static final SegmentPool INSTANCE = new SegmentPool();
      private static final Segment LOCK = new Segment(new byte[0], 0, 0, false, false);
      private static final int MAX_SIZE = 65536;
      private static final AtomicReference<Segment>[] hashBuckets;
  
      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++) {
              int i2 = i;
              atomicReferenceArr[i] = new AtomicReference<>();
          }
          hashBuckets = atomicReferenceArr;
      }
  
      private SegmentPool() {
      }
  
      private final AtomicReference<Segment> firstRef() {
          Thread currentThread = Thread.currentThread();
          Intrinsics.checkNotNullExpressionValue(currentThread, "Thread.currentThread()");
          return hashBuckets[(int) (currentThread.getId() & (((long) HASH_BUCKET_COUNT) - 1))];
      }
  
      @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());
          } else if (!segment.shared && (segment2 = firstRef.get()) != LOCK) {
              int i = segment2 != null ? segment2.limit : 0;
              if (i < MAX_SIZE) {
                  segment.next = segment2;
                  segment.pos = 0;
                  segment.limit = i + 8192;
                  if (!SegmentPool$$ExternalSyntheticBackportWithForwarding0.m((firstRef = INSTANCE.firstRef()), segment2, segment)) {
                      Segment segment3 = null;
                      segment.next = null;
                  }
              }
          }
      }
  
      @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((Object) null);
              return new Segment();
          }
          firstRef.set(andSet.next);
          Segment segment2 = null;
          andSet.next = null;
          andSet.limit = 0;
          return andSet;
      }
  
      public final int getByteCount() {
          Segment segment = firstRef().get();
          if (segment != null) {
              return segment.limit;
          }
          return 0;
      }
  
      public final int getMAX_SIZE() {
          return MAX_SIZE;
      }
  }
  