package p025.p026;

import java.lang.reflect.Method;
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 p138.p139.p143.p144.C2803;
import p402.InterfaceC6540;
import p402.p405.InterfaceC6578;
import p402.p420.C6703;

/* JADX INFO: renamed from: އ.֏.ތ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public final class C1314 extends AbstractC1353 {
    public static volatile Executor pool;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public static final int f4451;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public static final C1314 f4452 = new C1314();

    /* JADX INFO: renamed from: އ.֏.ތ$֏, reason: contains not printable characters */
    public static final class ThreadFactoryC1315 implements ThreadFactory {

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final /* synthetic */ AtomicInteger f4453;

        public ThreadFactoryC1315(AtomicInteger atomicInteger) {
            this.f4453 = atomicInteger;
        }

        @Override // java.util.concurrent.ThreadFactory
        public final Thread newThread(Runnable runnable) {
            StringBuilder sbM4889 = C2803.m4889("CommonPool-worker-");
            sbM4889.append(this.f4453.incrementAndGet());
            Thread thread = new Thread(runnable, sbM4889.toString());
            thread.setDaemon(true);
            return thread;
        }
    }

    static {
        String property;
        int iIntValue;
        try {
            property = System.getProperty("kotlinx.coroutines.default.parallelism");
        } catch (Throwable unused) {
            property = null;
        }
        if (property != null) {
            Integer numM9888 = C6703.m9888(property);
            if (numM9888 == null || numM9888.intValue() < 1) {
                throw new IllegalStateException(C2803.m4879("Expected positive number in kotlinx.coroutines.default.parallelism, but has ", property).toString());
            }
            iIntValue = numM9888.intValue();
        } else {
            iIntValue = -1;
        }
        f4451 = iIntValue;
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable
    public void close() {
        throw new IllegalStateException("Close cannot be invoked on CommonPool".toString());
    }

    @Override // p025.p026.AbstractC1323
    public String toString() {
        return "CommonPool";
    }

    @Override // p025.p026.AbstractC1323
    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public void mo2643(InterfaceC6578 interfaceC6578, Runnable runnable) {
        try {
            Executor executorM2646 = pool;
            if (executorM2646 == null) {
                executorM2646 = m2646();
            }
            executorM2646.execute(runnable);
        } catch (RejectedExecutionException unused) {
            RunnableC1330.f4471.m2676(runnable);
        }
    }

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public final ExecutorService m2644() {
        return Executors.newFixedThreadPool(m2647(), new ThreadFactoryC1315(new AtomicInteger()));
    }

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public final ExecutorService m2645() {
        Class<?> cls;
        ExecutorService executorService;
        Integer num;
        if (System.getSecurityManager() != null) {
            return m2644();
        }
        ExecutorService executorService2 = null;
        try {
            cls = Class.forName("java.util.concurrent.ForkJoinPool");
        } catch (Throwable unused) {
            cls = null;
        }
        if (cls == null) {
            return m2644();
        }
        if (f4451 < 0) {
            try {
                Method method = cls.getMethod("commonPool", new Class[0]);
                Object objInvoke = method != null ? method.invoke(null, new Object[0]) : null;
                if (!(objInvoke instanceof ExecutorService)) {
                    objInvoke = null;
                }
                executorService = (ExecutorService) objInvoke;
            } catch (Throwable unused2) {
                executorService = null;
            }
            if (executorService != null) {
                if (f4452 == null) {
                    throw null;
                }
                executorService.submit(RunnableC1316.f4454);
                try {
                    Object objInvoke2 = cls.getMethod("getPoolSize", new Class[0]).invoke(executorService, new Object[0]);
                    if (!(objInvoke2 instanceof Integer)) {
                        objInvoke2 = null;
                    }
                    num = (Integer) objInvoke2;
                } catch (Throwable unused3) {
                    num = null;
                }
                if (!(num != null && num.intValue() >= 1)) {
                    executorService = null;
                }
                if (executorService != null) {
                    return executorService;
                }
            }
        }
        try {
            Object objNewInstance = cls.getConstructor(Integer.TYPE).newInstance(Integer.valueOf(f4452.m2647()));
            if (!(objNewInstance instanceof ExecutorService)) {
                objNewInstance = null;
            }
            executorService2 = (ExecutorService) objNewInstance;
        } catch (Throwable unused4) {
        }
        return executorService2 != null ? executorService2 : m2644();
    }

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public final synchronized Executor m2646() {
        Executor executorM2645;
        executorM2645 = pool;
        if (executorM2645 == null) {
            executorM2645 = m2645();
            pool = executorM2645;
        }
        return executorM2645;
    }

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public final int m2647() {
        Integer numValueOf = Integer.valueOf(f4451);
        if (!(numValueOf.intValue() > 0)) {
            numValueOf = null;
        }
        if (numValueOf != null) {
            return numValueOf.intValue();
        }
        int iAvailableProcessors = Runtime.getRuntime().availableProcessors() - 1;
        return iAvailableProcessors >= 1 ? iAvailableProcessors : 1;
    }
}
