package defpackage;

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

/* renamed from: ʿᵮᵗʜ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class RunnableC0457 extends AbstractC2584 implements Runnable {
    private static volatile Thread _thread;
    private static volatile int debugStatus;

    /* renamed from: ˎˑː, reason: contains not printable characters */
    public static final RunnableC0457 f2516;

    /* renamed from: ᵮᵠـˌ, reason: contains not printable characters */
    public static final long f2517;

    static {
        Long l;
        RunnableC0457 runnableC0457 = new RunnableC0457();
        f2516 = runnableC0457;
        runnableC0457.m2663(false);
        try {
            l = Long.getLong("kotlinx.coroutines.DefaultExecutor.keepAlive", 1000L);
        } catch (SecurityException unused) {
            l = 1000L;
        }
        f2517 = TimeUnit.MILLISECONDS.toNanos(l.longValue());
    }

    @Override // java.lang.Runnable
    public final void run() {
        boolean zM6486;
        AbstractC1407.f5763.set(this);
        try {
            synchronized (this) {
                int i = debugStatus;
                if (i == 2 || i == 3) {
                    if (zM6486) {
                        return;
                    } else {
                        return;
                    }
                }
                debugStatus = 1;
                notifyAll();
                long j = Long.MAX_VALUE;
                while (true) {
                    Thread.interrupted();
                    long jMo2665 = mo2665();
                    if (jMo2665 == Long.MAX_VALUE) {
                        long jNanoTime = System.nanoTime();
                        if (j == Long.MAX_VALUE) {
                            j = f2517 + jNanoTime;
                        }
                        long j2 = j - jNanoTime;
                        if (j2 <= 0) {
                            _thread = null;
                            m2060();
                            if (m6486()) {
                                return;
                            }
                            mo2061();
                            return;
                        }
                        if (jMo2665 > j2) {
                            jMo2665 = j2;
                        }
                    } else {
                        j = Long.MAX_VALUE;
                    }
                    if (jMo2665 > 0) {
                        int i2 = debugStatus;
                        if (i2 == 2 || i2 == 3) {
                            _thread = null;
                            m2060();
                            if (m6486()) {
                                return;
                            }
                            mo2061();
                            return;
                        }
                        LockSupport.parkNanos(this, jMo2665);
                    }
                }
            }
        } finally {
            _thread = null;
            m2060();
            if (!m6486()) {
                mo2061();
            }
        }
    }

    @Override // defpackage.AbstractC2584, defpackage.AbstractC0685
    public final void shutdown() {
        debugStatus = 4;
        super.shutdown();
    }

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

    @Override // defpackage.AbstractC2584
    /* renamed from: ʿᵘˆ, reason: contains not printable characters */
    public final void mo2058(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.mo2058(runnable);
    }

    @Override // defpackage.AbstractC2584
    /* renamed from: ˉᵴﹶ, reason: contains not printable characters */
    public final void mo2059(long j, AbstractRunnableC0718 abstractRunnableC0718) {
        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");
    }

    /* renamed from: ˎᵶᵹ, reason: contains not printable characters */
    public final synchronized void m2060() {
        int i = debugStatus;
        if (i == 2 || i == 3) {
            debugStatus = 3;
            m6482();
            notifyAll();
        }
    }

    @Override // defpackage.AbstractC2584
    /* renamed from: ᵎʾ, reason: contains not printable characters */
    public final Thread mo2061() {
        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(RunnableC0457.class.getClassLoader());
                thread.setDaemon(true);
                thread.start();
            }
        }
        return thread;
    }

    @Override // defpackage.AbstractC2584, defpackage.InterfaceC5297
    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public final InterfaceC3451 mo2062(long j, Runnable runnable, InterfaceC2262 interfaceC2262) {
        long j2 = j > 0 ? j >= 9223372036854L ? Long.MAX_VALUE : 1000000 * j : 0L;
        if (j2 >= 4611686018427387903L) {
            return C0281.f1879;
        }
        long jNanoTime = System.nanoTime();
        C0200 c0200 = new C0200(runnable, j2 + jNanoTime);
        m6481(jNanoTime, c0200);
        return c0200;
    }
}
