package Q1;

import androidx.datastore.preferences.protobuf.C0432j;
import com.google.android.gms.internal.measurement.C1;
import java.util.concurrent.locks.ReentrantLock;

/* JADX INFO: loaded from: classes.dex */
public final class k {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final int f5589a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final O6.a f5590b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final ReentrantLock f5591c = new ReentrantLock();

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f5592d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public boolean f5593e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final i[] f5594f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final i7.j f5595g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final C0432j f5596h;

    public k(int i, O6.a aVar) {
        this.f5589a = i;
        this.f5590b = aVar;
        this.f5594f = new i[i];
        int i5 = i7.k.f13593a;
        this.f5595g = new i7.j(i, 0);
        this.f5596h = new C0432j(i);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object a(G6.c cVar) throws Throwable {
        j jVar;
        k kVar;
        if (cVar instanceof j) {
            jVar = (j) cVar;
            int i = jVar.f5588w;
            if ((i & Integer.MIN_VALUE) != 0) {
                jVar.f5588w = i - Integer.MIN_VALUE;
            } else {
                jVar = new j(this, cVar);
            }
        }
        Object obj = jVar.f5586u;
        F6.a aVar = F6.a.f2580q;
        int i5 = jVar.f5588w;
        if (i5 == 0) {
            C1.N(obj);
            jVar.f5585t = this;
            jVar.f5588w = 1;
            if (this.f5595g.c(jVar) == aVar) {
                return aVar;
            }
            kVar = this;
        } else {
            if (i5 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            kVar = jVar.f5585t;
            C1.N(obj);
        }
        try {
            ReentrantLock reentrantLock = kVar.f5591c;
            C0432j c0432j = kVar.f5596h;
            reentrantLock.lock();
            try {
                if (kVar.f5593e) {
                    android.support.v4.media.session.a.t(21, "Connection pool is closed");
                    throw null;
                }
                if (c0432j.f8096b == c0432j.f8097c && kVar.f5592d < kVar.f5589a) {
                    i iVar = new i((X1.a) kVar.f5590b.a());
                    int i8 = kVar.f5592d;
                    kVar.f5592d = i8 + 1;
                    kVar.f5594f[i8] = iVar;
                    c0432j.b(iVar);
                }
                int i9 = c0432j.f8096b;
                if (i9 == c0432j.f8097c) {
                    throw new ArrayIndexOutOfBoundsException();
                }
                Object[] objArr = (Object[]) c0432j.f8099e;
                Object obj2 = objArr[i9];
                objArr[i9] = null;
                c0432j.f8096b = (i9 + 1) & c0432j.f8098d;
                return (i) obj2;
            } finally {
                reentrantLock.unlock();
            }
        } catch (Throwable th) {
            kVar.f5595g.e();
            throw th;
        }
    }

    public final void b() {
        ReentrantLock reentrantLock = this.f5591c;
        reentrantLock.lock();
        try {
            this.f5593e = true;
            for (i iVar : this.f5594f) {
                if (iVar != null) {
                    iVar.close();
                }
            }
        } finally {
            reentrantLock.unlock();
        }
    }

    public final void c(StringBuilder sb) {
        C0432j c0432j = this.f5596h;
        ReentrantLock reentrantLock = this.f5591c;
        reentrantLock.lock();
        try {
            C6.c cVar = new C6.c(10);
            int iX = c0432j.X();
            for (int i = 0; i < iX; i++) {
                cVar.add(c0432j.d(i));
            }
            C6.c cVarD = C1.d(cVar);
            sb.append('\t' + toString() + " (");
            sb.append("capacity=" + this.f5589a + ", ");
            StringBuilder sb2 = new StringBuilder();
            sb2.append("permits=");
            i7.j jVar = this.f5595g;
            jVar.getClass();
            sb2.append(Math.max(i7.i.f13590w.get(jVar), 0));
            sb2.append(", ");
            sb.append(sb2.toString());
            sb.append("queue=(size=" + cVarD.a() + ")[" + B6.k.m0(cVarD, null, null, null, null, 63) + "], ");
            sb.append(")");
            sb.append('\n');
            i[] iVarArr = this.f5594f;
            int length = iVarArr.length;
            int i5 = 0;
            for (int i8 = 0; i8 < length; i8++) {
                i iVar = iVarArr[i8];
                i5++;
                StringBuilder sb3 = new StringBuilder();
                sb3.append("\t\t[");
                sb3.append(i5);
                sb3.append("] - ");
                sb3.append(iVar != null ? iVar.f5581q.toString() : null);
                sb.append(sb3.toString());
                sb.append('\n');
                if (iVar != null) {
                    iVar.g(sb);
                }
            }
            reentrantLock.unlock();
        } catch (Throwable th) {
            reentrantLock.unlock();
            throw th;
        }
    }

    public final void d(i iVar) {
        P6.g.e(iVar, "connection");
        ReentrantLock reentrantLock = this.f5591c;
        reentrantLock.lock();
        try {
            this.f5596h.b(iVar);
            reentrantLock.unlock();
            this.f5595g.e();
        } catch (Throwable th) {
            reentrantLock.unlock();
            throw th;
        }
    }
}
