157 lines
5.3 KiB
Java
157 lines
5.3 KiB
Java
package s.a;
|
|
|
|
import d0.d0.f;
|
|
import d0.g0.s;
|
|
import java.lang.reflect.Method;
|
|
import java.util.Objects;
|
|
import java.util.concurrent.Executor;
|
|
import java.util.concurrent.ExecutorService;
|
|
import java.util.concurrent.Executors;
|
|
import java.util.concurrent.RejectedExecutionException;
|
|
import java.util.concurrent.ThreadFactory;
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
import kotlin.coroutines.CoroutineContext;
|
|
import kotlinx.coroutines.ExecutorCoroutineDispatcher;
|
|
/* compiled from: CommonPool.kt */
|
|
public final class r extends ExecutorCoroutineDispatcher {
|
|
public static final int i;
|
|
public static final r j = new r();
|
|
public static volatile Executor pool;
|
|
|
|
/* compiled from: CommonPool.kt */
|
|
public static final class a implements ThreadFactory {
|
|
public final /* synthetic */ AtomicInteger i;
|
|
|
|
public a(AtomicInteger atomicInteger) {
|
|
this.i = atomicInteger;
|
|
}
|
|
|
|
@Override // java.util.concurrent.ThreadFactory
|
|
public final Thread newThread(Runnable runnable) {
|
|
StringBuilder K = c.d.b.a.a.K("CommonPool-worker-");
|
|
K.append(this.i.incrementAndGet());
|
|
Thread thread = new Thread(runnable, K.toString());
|
|
thread.setDaemon(true);
|
|
return thread;
|
|
}
|
|
}
|
|
|
|
static {
|
|
String str;
|
|
int i2;
|
|
try {
|
|
str = System.getProperty("kotlinx.coroutines.default.parallelism");
|
|
} catch (Throwable unused) {
|
|
str = null;
|
|
}
|
|
if (str != null) {
|
|
Integer intOrNull = s.toIntOrNull(str);
|
|
if (intOrNull == null || intOrNull.intValue() < 1) {
|
|
throw new IllegalStateException(c.d.b.a.a.s("Expected positive number in kotlinx.coroutines.default.parallelism, but has ", str).toString());
|
|
}
|
|
i2 = intOrNull.intValue();
|
|
} else {
|
|
i2 = -1;
|
|
}
|
|
i = i2;
|
|
}
|
|
|
|
public final ExecutorService I() {
|
|
return Executors.newFixedThreadPool(M(), new a(new AtomicInteger()));
|
|
}
|
|
|
|
public final ExecutorService K() {
|
|
Class<?> cls;
|
|
ExecutorService executorService;
|
|
Integer num;
|
|
if (System.getSecurityManager() != null) {
|
|
return I();
|
|
}
|
|
ExecutorService executorService2 = null;
|
|
try {
|
|
cls = Class.forName("java.util.concurrent.ForkJoinPool");
|
|
} catch (Throwable unused) {
|
|
cls = null;
|
|
}
|
|
if (cls == null) {
|
|
return I();
|
|
}
|
|
if (i < 0) {
|
|
try {
|
|
Method method = cls.getMethod("commonPool", new Class[0]);
|
|
Object invoke = method != null ? method.invoke(null, new Object[0]) : null;
|
|
if (!(invoke instanceof ExecutorService)) {
|
|
invoke = null;
|
|
}
|
|
executorService = (ExecutorService) invoke;
|
|
} catch (Throwable unused2) {
|
|
executorService = null;
|
|
}
|
|
if (executorService != null) {
|
|
Objects.requireNonNull(j);
|
|
executorService.submit(s.i);
|
|
try {
|
|
Object invoke2 = cls.getMethod("getPoolSize", new Class[0]).invoke(executorService, new Object[0]);
|
|
if (!(invoke2 instanceof Integer)) {
|
|
invoke2 = null;
|
|
}
|
|
num = (Integer) invoke2;
|
|
} catch (Throwable unused3) {
|
|
num = null;
|
|
}
|
|
if (!(num != null && num.intValue() >= 1)) {
|
|
executorService = null;
|
|
}
|
|
if (executorService != null) {
|
|
return executorService;
|
|
}
|
|
}
|
|
}
|
|
try {
|
|
Object newInstance = cls.getConstructor(Integer.TYPE).newInstance(Integer.valueOf(j.M()));
|
|
if (!(newInstance instanceof ExecutorService)) {
|
|
newInstance = null;
|
|
}
|
|
executorService2 = (ExecutorService) newInstance;
|
|
} catch (Throwable unused4) {
|
|
}
|
|
return executorService2 != null ? executorService2 : I();
|
|
}
|
|
|
|
public final int M() {
|
|
Integer valueOf = Integer.valueOf(i);
|
|
if (!(valueOf.intValue() > 0)) {
|
|
valueOf = null;
|
|
}
|
|
return valueOf != null ? valueOf.intValue() : f.coerceAtLeast(Runtime.getRuntime().availableProcessors() - 1, 1);
|
|
}
|
|
|
|
@Override // java.io.Closeable, java.lang.AutoCloseable
|
|
public void close() {
|
|
throw new IllegalStateException("Close cannot be invoked on CommonPool".toString());
|
|
}
|
|
|
|
@Override // kotlinx.coroutines.CoroutineDispatcher
|
|
public void dispatch(CoroutineContext coroutineContext, Runnable runnable) {
|
|
try {
|
|
Executor executor = pool;
|
|
if (executor == null) {
|
|
synchronized (this) {
|
|
executor = pool;
|
|
if (executor == null) {
|
|
executor = K();
|
|
pool = executor;
|
|
}
|
|
}
|
|
}
|
|
executor.execute(runnable);
|
|
} catch (RejectedExecutionException unused) {
|
|
c0.o.S(runnable);
|
|
}
|
|
}
|
|
|
|
@Override // kotlinx.coroutines.CoroutineDispatcher, java.lang.Object
|
|
public String toString() {
|
|
return "CommonPool";
|
|
}
|
|
}
|