package n9; import com.google.android.gms.common.api.Api; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; import java.util.Iterator; import java.util.concurrent.ExecutorService; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import n9.d0; /* loaded from: classes2.dex */ public final class q { /* renamed from: c, reason: collision with root package name */ private Runnable f12505c; /* renamed from: d, reason: collision with root package name */ private ExecutorService f12506d; /* renamed from: a, reason: collision with root package name */ private int f12503a = 64; /* renamed from: b, reason: collision with root package name */ private int f12504b = 5; /* renamed from: e, reason: collision with root package name */ private final Deque f12507e = new ArrayDeque(); /* renamed from: f, reason: collision with root package name */ private final Deque f12508f = new ArrayDeque(); /* renamed from: g, reason: collision with root package name */ private final Deque f12509g = new ArrayDeque(); private d0.a d(String str) { for (d0.a aVar : this.f12508f) { if (aVar.o().equals(str)) { return aVar; } } for (d0.a aVar2 : this.f12507e) { if (aVar2.o().equals(str)) { return aVar2; } } return null; } private void e(Deque deque, Object obj) { Runnable runnable; synchronized (this) { if (!deque.remove(obj)) { throw new AssertionError("Call wasn't in-flight!"); } runnable = this.f12505c; } if (h() || runnable == null) { return; } runnable.run(); } private boolean h() { int i10; boolean z10; ArrayList arrayList = new ArrayList(); synchronized (this) { Iterator it = this.f12507e.iterator(); while (it.hasNext()) { d0.a aVar = (d0.a) it.next(); if (this.f12508f.size() >= this.f12503a) { break; } if (aVar.l().get() < this.f12504b) { it.remove(); aVar.l().incrementAndGet(); arrayList.add(aVar); this.f12508f.add(aVar); } } z10 = i() > 0; } int size = arrayList.size(); for (i10 = 0; i10 < size; i10++) { ((d0.a) arrayList.get(i10)).m(c()); } return z10; } void a(d0.a aVar) { d0.a d10; synchronized (this) { this.f12507e.add(aVar); if (!aVar.n().f12317d && (d10 = d(aVar.o())) != null) { aVar.p(d10); } } h(); } synchronized void b(d0 d0Var) { this.f12509g.add(d0Var); } public synchronized ExecutorService c() { if (this.f12506d == null) { this.f12506d = new ThreadPoolExecutor(0, Api.BaseClientBuilder.API_PRIORITY_OTHER, 60L, TimeUnit.SECONDS, new SynchronousQueue(), o9.e.I("OkHttp Dispatcher", false)); } return this.f12506d; } void f(d0.a aVar) { aVar.l().decrementAndGet(); e(this.f12508f, aVar); } void g(d0 d0Var) { e(this.f12509g, d0Var); } public synchronized int i() { return this.f12508f.size() + this.f12509g.size(); } }