package f0; import d0.z.d.m; import f0.f0.b; import f0.f0.c; import f0.f0.g.e; import java.io.InterruptedIOException; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Deque; import java.util.Iterator; import java.util.Objects; import java.util.concurrent.ExecutorService; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.SynchronousQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; /* compiled from: Dispatcher.kt */ public final class q { public ExecutorService a; public final ArrayDeque b = new ArrayDeque<>(); /* renamed from: c reason: collision with root package name */ public final ArrayDeque f2777c = new ArrayDeque<>(); public final ArrayDeque d = new ArrayDeque<>(); public final synchronized void a() { Iterator it = this.b.iterator(); while (it.hasNext()) { it.next().k.cancel(); } Iterator it2 = this.f2777c.iterator(); while (it2.hasNext()) { it2.next().k.cancel(); } Iterator it3 = this.d.iterator(); while (it3.hasNext()) { it3.next().cancel(); } } public final void b(Deque deque, T t) { synchronized (this) { if (!deque.remove(t)) { throw new AssertionError("Call wasn't in-flight!"); } } d(); } public final void c(e.a aVar) { m.checkParameterIsNotNull(aVar, "call"); aVar.i.decrementAndGet(); b(this.f2777c, aVar); } /* JADX WARNING: Removed duplicated region for block: B:25:0x0067 */ public final boolean d() { int size; int size2; int i; ExecutorService executorService; byte[] bArr = c.a; ArrayList arrayList = new ArrayList(); synchronized (this) { Iterator it = this.b.iterator(); m.checkExpressionValueIsNotNull(it, "readyAsyncCalls.iterator()"); while (true) { if (!it.hasNext()) { break; } e.a next = it.next(); if (this.f2777c.size() >= 64) { break; } else if (next.i.get() < 5) { it.remove(); next.i.incrementAndGet(); m.checkExpressionValueIsNotNull(next, "asyncCall"); arrayList.add(next); this.f2777c.add(next); } } synchronized (this) { size = this.f2777c.size() + this.d.size(); } size2 = arrayList.size(); for (i = 0; i < size2; i++) { e.a aVar = (e.a) arrayList.get(i); synchronized (this) { if (this.a == null) { TimeUnit timeUnit = TimeUnit.SECONDS; SynchronousQueue synchronousQueue = new SynchronousQueue(); String str = c.g + " Dispatcher"; m.checkParameterIsNotNull(str, "name"); this.a = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60, timeUnit, synchronousQueue, new b(str, false)); } executorService = this.a; if (executorService == null) { m.throwNpe(); } } Objects.requireNonNull(aVar); m.checkParameterIsNotNull(executorService, "executorService"); q qVar = aVar.k.f2731x.l; byte[] bArr2 = c.a; try { executorService.execute(aVar); } catch (RejectedExecutionException e) { InterruptedIOException interruptedIOException = new InterruptedIOException("executor rejected"); interruptedIOException.initCause(e); aVar.k.l(interruptedIOException); aVar.j.b(aVar.k, interruptedIOException); aVar.k.f2731x.l.c(aVar); } catch (Throwable th) { aVar.k.f2731x.l.c(aVar); throw th; } } return r1; } boolean z2 = size > 0; size2 = arrayList.size(); while (i < size2) { } return z2; } }