package com.mbridge.msdk.thrid.okio; import android.support.v4.media.session.PlaybackStateCompat; import androidx.annotation.Nullable; /* loaded from: classes4.dex */ final class SegmentPool { static final long MAX_SIZE = 65536; static long byteCount; @Nullable static Segment next; private SegmentPool() { } public static Segment take() { synchronized (SegmentPool.class) { try { Segment segment = next; if (segment != null) { next = segment.next; segment.next = null; byteCount -= PlaybackStateCompat.ACTION_PLAY_FROM_URI; return segment; } return new Segment(); } catch (Throwable th) { throw th; } } } public static void recycle(Segment segment) { if (segment.next != null || segment.prev != null) { throw new IllegalArgumentException(); } if (segment.shared) { return; } synchronized (SegmentPool.class) { try { long j = byteCount; if (j + PlaybackStateCompat.ACTION_PLAY_FROM_URI > 65536) { return; } byteCount = j + PlaybackStateCompat.ACTION_PLAY_FROM_URI; segment.next = next; segment.limit = 0; segment.pos = 0; next = segment; } catch (Throwable th) { throw th; } } } }