package o;

import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.Up, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class RunnableC0534Up extends AbstractC0411Pw implements Runnable {
    private static volatile Thread _thread;
    private static volatile int debugStatus;
    public static final RunnableC0534Up s;
    public static final long t;

    static {
        Long l;
        RunnableC0534Up runnableC0534Up = new RunnableC0534Up();
        s = runnableC0534Up;
        runnableC0534Up.a0(false);
        TimeUnit timeUnit = TimeUnit.MILLISECONDS;
        try {
            l = Long.getLong("kotlinx.coroutines.DefaultExecutor.keepAlive", 1000L);
        } catch (SecurityException unused) {
            l = 1000L;
        }
        t = timeUnit.toNanos(l.longValue());
    }

    @Override // o.AbstractC0437Qw
    public final Thread Z() {
        Thread thread;
        Thread thread2 = _thread;
        if (thread2 != null) {
            return thread2;
        }
        synchronized (this) {
            thread = _thread;
            if (thread == null) {
                thread = new Thread(this, "kotlinx.coroutines.DefaultExecutor");
                _thread = thread;
                thread.setContextClassLoader(RunnableC0534Up.class.getClassLoader());
                thread.setDaemon(true);
                thread.start();
            }
        }
        return thread;
    }

    @Override // o.AbstractC0437Qw
    public final void d0(long j, AbstractRunnableC0359Nw abstractRunnableC0359Nw) {
        throw new RejectedExecutionException("DefaultExecutor was shut down. This error indicates that Dispatchers.shutdown() was invoked prior to completion of exiting coroutines, leaving coroutines in incomplete state. Please refer to Dispatchers.shutdown documentation for more details");
    }

    @Override // o.AbstractC0411Pw
    public final void e0(Runnable runnable) {
        if (debugStatus == 4) {
            throw new RejectedExecutionException("DefaultExecutor was shut down. This error indicates that Dispatchers.shutdown() was invoked prior to completion of exiting coroutines, leaving coroutines in incomplete state. Please refer to Dispatchers.shutdown documentation for more details");
        }
        super.e0(runnable);
    }

    public final synchronized void j0() {
        int i = debugStatus;
        if (i == 2 || i == 3) {
            debugStatus = 3;
            AbstractC0411Pw.p.set(this, null);
            AbstractC0411Pw.q.set(this, null);
            notifyAll();
        }
    }

    @Override // java.lang.Runnable
    public final void run() {
        boolean zH0;
        AbstractC1688kf0.a.set(this);
        try {
            synchronized (this) {
                int i = debugStatus;
                if (i == 2 || i == 3) {
                    if (zH0) {
                        return;
                    } else {
                        return;
                    }
                }
                debugStatus = 1;
                notifyAll();
                long j = Long.MAX_VALUE;
                while (true) {
                    Thread.interrupted();
                    long jB0 = b0();
                    if (jB0 == Long.MAX_VALUE) {
                        long jNanoTime = System.nanoTime();
                        if (j == Long.MAX_VALUE) {
                            j = t + jNanoTime;
                        }
                        long j2 = j - jNanoTime;
                        if (j2 <= 0) {
                            _thread = null;
                            j0();
                            if (h0()) {
                                return;
                            }
                            Z();
                            return;
                        }
                        if (jB0 > j2) {
                            jB0 = j2;
                        }
                    } else {
                        j = Long.MAX_VALUE;
                    }
                    if (jB0 > 0) {
                        int i2 = debugStatus;
                        if (i2 == 2 || i2 == 3) {
                            _thread = null;
                            j0();
                            if (h0()) {
                                return;
                            }
                            Z();
                            return;
                        }
                        LockSupport.parkNanos(this, jB0);
                    }
                }
            }
        } finally {
            _thread = null;
            j0();
            if (!h0()) {
                Z();
            }
        }
    }

    @Override // o.AbstractC0411Pw, o.AbstractC0437Qw
    public final void shutdown() {
        debugStatus = 4;
        super.shutdown();
    }

    @Override // o.AbstractC2842wn
    public final String toString() {
        return "DefaultExecutor";
    }

    @Override // o.AbstractC0411Pw, o.InterfaceC0405Pq
    public final InterfaceC2567ts u(long j, Ef0 ef0, InterfaceC2747vn interfaceC2747vn) {
        long j2 = j > 0 ? j >= 9223372036854L ? Long.MAX_VALUE : 1000000 * j : 0L;
        if (j2 >= 4611686018427387903L) {
            return C2713vS.l;
        }
        long jNanoTime = System.nanoTime();
        C0333Mw c0333Mw = new C0333Mw(j2 + jNanoTime, ef0);
        i0(jNanoTime, c0333Mw);
        return c0333Mw;
    }
}
