2021-06-27 20:44:35 +00:00
|
|
|
package f0;
|
|
|
|
|
2021-11-08 18:25:28 +00:00
|
|
|
import androidx.core.app.NotificationCompat;
|
|
|
|
import com.discord.models.domain.ModelAuditLogEntry;
|
|
|
|
import d0.z.d.m;
|
|
|
|
import f0.e0.b;
|
|
|
|
import f0.e0.c;
|
|
|
|
import f0.e0.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 */
|
2022-03-02 20:59:20 +00:00
|
|
|
/* loaded from: classes3.dex */
|
2021-11-08 18:25:28 +00:00
|
|
|
public final class q {
|
|
|
|
public ExecutorService a;
|
|
|
|
|
2021-12-21 23:37:30 +00:00
|
|
|
/* renamed from: b reason: collision with root package name */
|
2022-03-22 15:40:06 +00:00
|
|
|
public final ArrayDeque<e.a> f3655b = new ArrayDeque<>();
|
2021-12-21 23:37:30 +00:00
|
|
|
public final ArrayDeque<e.a> c = new ArrayDeque<>();
|
2021-11-08 18:25:28 +00:00
|
|
|
public final ArrayDeque<e> d = new ArrayDeque<>();
|
|
|
|
|
|
|
|
public final synchronized void a() {
|
2022-03-22 15:40:06 +00:00
|
|
|
Iterator<e.a> it = this.f3655b.iterator();
|
2021-11-08 18:25:28 +00:00
|
|
|
while (it.hasNext()) {
|
2021-12-17 22:03:14 +00:00
|
|
|
it.next().l.cancel();
|
2021-11-08 18:25:28 +00:00
|
|
|
}
|
2021-12-21 23:37:30 +00:00
|
|
|
Iterator<e.a> it2 = this.c.iterator();
|
2021-11-08 18:25:28 +00:00
|
|
|
while (it2.hasNext()) {
|
2021-12-17 22:03:14 +00:00
|
|
|
it2.next().l.cancel();
|
2021-11-08 18:25:28 +00:00
|
|
|
}
|
|
|
|
Iterator<e> it3 = this.d.iterator();
|
|
|
|
while (it3.hasNext()) {
|
|
|
|
it3.next().cancel();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public final <T> void b(Deque<T> deque, T t) {
|
|
|
|
synchronized (this) {
|
|
|
|
if (!deque.remove(t)) {
|
|
|
|
throw new AssertionError("Call wasn't in-flight!");
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-08 18:25:28 +00:00
|
|
|
d();
|
|
|
|
}
|
|
|
|
|
|
|
|
public final void c(e.a aVar) {
|
|
|
|
m.checkParameterIsNotNull(aVar, NotificationCompat.CATEGORY_CALL);
|
2021-12-17 22:03:14 +00:00
|
|
|
aVar.j.decrementAndGet();
|
2021-12-21 23:37:30 +00:00
|
|
|
b(this.c, aVar);
|
2021-11-08 18:25:28 +00:00
|
|
|
}
|
|
|
|
|
2022-03-02 20:59:20 +00:00
|
|
|
/* JADX WARN: Removed duplicated region for block: B:25:0x0067 */
|
|
|
|
/*
|
|
|
|
Code decompiled incorrectly, please refer to instructions dump.
|
|
|
|
*/
|
2021-11-08 18:25:28 +00:00
|
|
|
public final boolean d() {
|
|
|
|
int size;
|
|
|
|
int size2;
|
|
|
|
int i;
|
|
|
|
ExecutorService executorService;
|
|
|
|
byte[] bArr = c.a;
|
|
|
|
ArrayList arrayList = new ArrayList();
|
|
|
|
synchronized (this) {
|
2022-03-22 15:40:06 +00:00
|
|
|
Iterator<e.a> it = this.f3655b.iterator();
|
2021-11-08 18:25:28 +00:00
|
|
|
m.checkExpressionValueIsNotNull(it, "readyAsyncCalls.iterator()");
|
2022-03-02 20:59:20 +00:00
|
|
|
while (it.hasNext()) {
|
2021-11-08 18:25:28 +00:00
|
|
|
e.a next = it.next();
|
2021-12-21 23:37:30 +00:00
|
|
|
if (this.c.size() >= 64) {
|
2021-11-08 18:25:28 +00:00
|
|
|
break;
|
2021-12-17 22:03:14 +00:00
|
|
|
} else if (next.j.get() < 5) {
|
2021-11-08 18:25:28 +00:00
|
|
|
it.remove();
|
2021-12-17 22:03:14 +00:00
|
|
|
next.j.incrementAndGet();
|
2021-11-08 18:25:28 +00:00
|
|
|
m.checkExpressionValueIsNotNull(next, "asyncCall");
|
|
|
|
arrayList.add(next);
|
2021-12-21 23:37:30 +00:00
|
|
|
this.c.add(next);
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-08 18:25:28 +00:00
|
|
|
synchronized (this) {
|
2021-12-21 23:37:30 +00:00
|
|
|
size = this.c.size() + this.d.size();
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
2021-11-08 18:25:28 +00:00
|
|
|
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, ModelAuditLogEntry.CHANGE_KEY_NAME);
|
2022-03-02 20:59:20 +00:00
|
|
|
this.a = new ThreadPoolExecutor(0, Integer.MAX_VALUE, 60L, timeUnit, synchronousQueue, new b(str, false));
|
2021-11-08 18:25:28 +00:00
|
|
|
}
|
|
|
|
executorService = this.a;
|
|
|
|
if (executorService == null) {
|
|
|
|
m.throwNpe();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Objects.requireNonNull(aVar);
|
|
|
|
m.checkParameterIsNotNull(executorService, "executorService");
|
2022-03-22 15:40:06 +00:00
|
|
|
q qVar = aVar.l.f3596y.m;
|
2021-11-08 18:25:28 +00:00
|
|
|
byte[] bArr2 = c.a;
|
|
|
|
try {
|
2022-03-02 20:59:20 +00:00
|
|
|
try {
|
|
|
|
executorService.execute(aVar);
|
|
|
|
} catch (RejectedExecutionException e) {
|
|
|
|
InterruptedIOException interruptedIOException = new InterruptedIOException("executor rejected");
|
|
|
|
interruptedIOException.initCause(e);
|
|
|
|
aVar.l.l(interruptedIOException);
|
|
|
|
aVar.k.b(aVar.l, interruptedIOException);
|
2022-03-22 15:40:06 +00:00
|
|
|
aVar.l.f3596y.m.c(aVar);
|
2022-03-02 20:59:20 +00:00
|
|
|
}
|
2021-11-08 18:25:28 +00:00
|
|
|
} catch (Throwable th) {
|
2022-03-22 15:40:06 +00:00
|
|
|
aVar.l.f3596y.m.c(aVar);
|
2021-11-08 18:25:28 +00:00
|
|
|
throw th;
|
|
|
|
}
|
2021-10-19 23:48:27 +00:00
|
|
|
}
|
2021-11-08 18:25:28 +00:00
|
|
|
return r1;
|
2021-10-19 23:48:27 +00:00
|
|
|
}
|
2021-11-08 18:25:28 +00:00
|
|
|
boolean z2 = size > 0;
|
|
|
|
size2 = arrayList.size();
|
|
|
|
while (i < size2) {
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
2021-11-08 18:25:28 +00:00
|
|
|
return z2;
|
2021-06-27 20:44:35 +00:00
|
|
|
}
|
|
|
|
}
|