package s.a; import d0.d0.f; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.LockSupport; import kotlin.coroutines.CoroutineContext; import s.a.p0; /* compiled from: DefaultExecutor.kt */ public final class c0 extends p0 implements Runnable { public static volatile Thread _thread; public static volatile int debugStatus; public static final long n; public static final c0 o; static { Long l; c0 c0Var = new c0(); o = c0Var; c0Var.M(false); TimeUnit timeUnit = TimeUnit.MILLISECONDS; try { l = Long.getLong("kotlinx.coroutines.DefaultExecutor.keepAlive", 1000); } catch (SecurityException unused) { l = 1000L; } n = timeUnit.toNanos(l.longValue()); } @Override // s.a.q0 public Thread R() { Thread thread = _thread; if (thread == null) { synchronized (this) { thread = _thread; if (thread == null) { thread = new Thread(this, "kotlinx.coroutines.DefaultExecutor"); _thread = thread; thread.setDaemon(true); thread.start(); } } } return thread; } public final synchronized void a0() { if (b0()) { debugStatus = 3; this._queue = null; this._delayed = null; notifyAll(); } } public final boolean b0() { int i = debugStatus; return i == 2 || i == 3; } @Override // java.lang.Runnable public void run() { boolean z2; q1 q1Var = q1.b; q1.a.set(this); Thread thread = null; try { synchronized (this) { if (b0()) { z2 = false; } else { z2 = true; debugStatus = 1; notifyAll(); } } if (z2) { long j = Long.MAX_VALUE; while (true) { Thread.interrupted(); long V = V(); if (V == Long.MAX_VALUE) { long nanoTime = System.nanoTime(); if (j == Long.MAX_VALUE) { j = n + nanoTime; } long j2 = j - nanoTime; if (j2 <= 0) { _thread = null; a0(); if (!U()) { R(); return; } return; } V = f.coerceAtMost(V, j2); } else { j = Long.MAX_VALUE; } if (V > 0) { if (b0()) { _thread = null; a0(); if (!U()) { R(); return; } return; } LockSupport.parkNanos(this, V); } } } } finally { _thread = thread; a0(); if (!U()) { R(); } } } @Override // s.a.p0, s.a.g0 public k0 w(long j, Runnable runnable, CoroutineContext coroutineContext) { long a = r0.a(j); if (a >= 4611686018427387903L) { return k1.i; } long nanoTime = System.nanoTime(); p0.b bVar = new p0.b(a + nanoTime, runnable); W(nanoTime, bVar); return bVar; } }