package F1;

import androidx.core.location.LocationRequestCompat;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/* JADX INFO: loaded from: classes.dex */
public final class M extends AbstractC0112b0 implements Runnable {

    /* JADX INFO: renamed from: I, reason: collision with root package name */
    public static final M f587I;

    /* JADX INFO: renamed from: L, reason: collision with root package name */
    private static final long f588L;
    private static volatile Thread _thread;
    private static volatile int debugStatus;

    static {
        Long l2;
        M m2 = new M();
        f587I = m2;
        AbstractC0110a0.G(m2, false, 1, null);
        TimeUnit timeUnit = TimeUnit.MILLISECONDS;
        try {
            l2 = Long.getLong("kotlinx.coroutines.DefaultExecutor.keepAlive", 1000L);
        } catch (SecurityException unused) {
            l2 = 1000L;
        }
        f588L = timeUnit.toNanos(l2.longValue());
    }

    private M() {
    }

    private final synchronized void k0() {
        if (m0()) {
            debugStatus = 3;
            f0();
            notifyAll();
        }
    }

    private final synchronized Thread l0() {
        Thread thread;
        thread = _thread;
        if (thread == null) {
            thread = new Thread(this, "kotlinx.coroutines.DefaultExecutor");
            _thread = thread;
            thread.setDaemon(true);
            thread.start();
        }
        return thread;
    }

    private final boolean m0() {
        int i2 = debugStatus;
        return i2 == 2 || i2 == 3;
    }

    private final synchronized boolean n0() {
        if (m0()) {
            return false;
        }
        debugStatus = 1;
        notifyAll();
        return true;
    }

    @Override // F1.AbstractC0114c0
    protected Thread P() {
        Thread thread = _thread;
        return thread == null ? l0() : thread;
    }

    @Override // java.lang.Runnable
    public void run() {
        boolean zC0;
        G0.f579a.d(this);
        AbstractC0113c.a();
        try {
            if (!n0()) {
                if (zC0) {
                    return;
                } else {
                    return;
                }
            }
            long j2 = Long.MAX_VALUE;
            while (true) {
                Thread.interrupted();
                long jK = K();
                if (jK == LocationRequestCompat.PASSIVE_INTERVAL) {
                    AbstractC0113c.a();
                    long jNanoTime = System.nanoTime();
                    if (j2 == LocationRequestCompat.PASSIVE_INTERVAL) {
                        j2 = f588L + jNanoTime;
                    }
                    long j3 = j2 - jNanoTime;
                    if (j3 <= 0) {
                        _thread = null;
                        k0();
                        AbstractC0113c.a();
                        if (c0()) {
                            return;
                        }
                        P();
                        return;
                    }
                    jK = kotlin.ranges.m.e(jK, j3);
                } else {
                    j2 = Long.MAX_VALUE;
                }
                if (jK > 0) {
                    if (m0()) {
                        _thread = null;
                        k0();
                        AbstractC0113c.a();
                        if (c0()) {
                            return;
                        }
                        P();
                        return;
                    }
                    AbstractC0113c.a();
                    LockSupport.parkNanos(this, jK);
                }
            }
        } finally {
            _thread = null;
            k0();
            AbstractC0113c.a();
            if (!c0()) {
                P();
            }
        }
    }
}
