package F1;

import androidx.core.location.LocationRequestCompat;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/* JADX INFO: renamed from: F1.b0, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC0112b0 extends AbstractC0114c0 implements Q {

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    private static final /* synthetic */ AtomicReferenceFieldUpdater f603y = AtomicReferenceFieldUpdater.newUpdater(AbstractC0112b0.class, Object.class, "_queue");

    /* JADX INFO: renamed from: H, reason: collision with root package name */
    private static final /* synthetic */ AtomicReferenceFieldUpdater f602H = AtomicReferenceFieldUpdater.newUpdater(AbstractC0112b0.class, Object.class, "_delayed");
    private volatile /* synthetic */ Object _queue = null;
    private volatile /* synthetic */ Object _delayed = null;
    private volatile /* synthetic */ int _isCompleted = 0;

    /* JADX INFO: renamed from: F1.b0$a */
    private final class a extends b {

        /* JADX INFO: renamed from: x, reason: collision with root package name */
        private final InterfaceC0131l f604x;

        public a(long j2, InterfaceC0131l interfaceC0131l) {
            super(j2);
            this.f604x = interfaceC0131l;
        }

        @Override // java.lang.Runnable
        public void run() {
            this.f604x.b(AbstractC0112b0.this, n1.s.f5871a);
        }

        @Override // F1.AbstractC0112b0.b
        public String toString() {
            return kotlin.jvm.internal.l.l(super.toString(), this.f604x);
        }
    }

    /* JADX INFO: renamed from: F1.b0$b */
    public static abstract class b implements Runnable, Comparable, X, kotlinx.coroutines.internal.x {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public long f606b;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        private Object f607g;

        /* JADX INFO: renamed from: r, reason: collision with root package name */
        private int f608r = -1;

        public b(long j2) {
            this.f606b = j2;
        }

        @Override // kotlinx.coroutines.internal.x
        public void a(kotlinx.coroutines.internal.w wVar) {
            if (!(this.f607g != AbstractC0118e0.f613a)) {
                throw new IllegalArgumentException("Failed requirement.");
            }
            this.f607g = wVar;
        }

        @Override // kotlinx.coroutines.internal.x
        public kotlinx.coroutines.internal.w c() {
            Object obj = this.f607g;
            if (obj instanceof kotlinx.coroutines.internal.w) {
                return (kotlinx.coroutines.internal.w) obj;
            }
            return null;
        }

        @Override // kotlinx.coroutines.internal.x
        public void d(int i2) {
            this.f608r = i2;
        }

        @Override // F1.X
        public final synchronized void dispose() {
            try {
                Object obj = this.f607g;
                if (obj == AbstractC0118e0.f613a) {
                    return;
                }
                c cVar = obj instanceof c ? (c) obj : null;
                if (cVar != null) {
                    cVar.g(this);
                }
                this.f607g = AbstractC0118e0.f613a;
            } catch (Throwable th) {
                throw th;
            }
        }

        @Override // kotlinx.coroutines.internal.x
        public int e() {
            return this.f608r;
        }

        @Override // java.lang.Comparable
        /* JADX INFO: renamed from: f, reason: merged with bridge method [inline-methods] */
        public int compareTo(b bVar) {
            long j2 = this.f606b - bVar.f606b;
            if (j2 > 0) {
                return 1;
            }
            return j2 < 0 ? -1 : 0;
        }

        public final synchronized int g(long j2, c cVar, AbstractC0112b0 abstractC0112b0) {
            if (this.f607g == AbstractC0118e0.f613a) {
                return 2;
            }
            synchronized (cVar) {
                try {
                    b bVar = (b) cVar.b();
                    if (abstractC0112b0.a0()) {
                        return 1;
                    }
                    if (bVar == null) {
                        cVar.f609b = j2;
                    } else {
                        long j3 = bVar.f606b;
                        if (j3 - j2 < 0) {
                            j2 = j3;
                        }
                        if (j2 - cVar.f609b > 0) {
                            cVar.f609b = j2;
                        }
                    }
                    long j4 = this.f606b;
                    long j5 = cVar.f609b;
                    if (j4 - j5 < 0) {
                        this.f606b = j5;
                    }
                    cVar.a(this);
                    return 0;
                } catch (Throwable th) {
                    throw th;
                }
            }
        }

        public final boolean h(long j2) {
            return j2 - this.f606b >= 0;
        }

        public String toString() {
            return "Delayed[nanos=" + this.f606b + ']';
        }
    }

    /* JADX INFO: renamed from: F1.b0$c */
    public static final class c extends kotlinx.coroutines.internal.w {

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public long f609b;

        public c(long j2) {
            this.f609b = j2;
        }
    }

    private final void U() {
        while (true) {
            Object obj = this._queue;
            if (obj == null) {
                if (androidx.concurrent.futures.a.a(f603y, this, null, AbstractC0118e0.f614b)) {
                    return;
                }
            } else if (obj instanceof kotlinx.coroutines.internal.k) {
                ((kotlinx.coroutines.internal.k) obj).d();
                return;
            } else {
                if (obj == AbstractC0118e0.f614b) {
                    return;
                }
                kotlinx.coroutines.internal.k kVar = new kotlinx.coroutines.internal.k(8, true);
                kVar.a((Runnable) obj);
                if (androidx.concurrent.futures.a.a(f603y, this, obj, kVar)) {
                    return;
                }
            }
        }
    }

    private final Runnable V() {
        while (true) {
            Object obj = this._queue;
            if (obj == null) {
                return null;
            }
            if (obj instanceof kotlinx.coroutines.internal.k) {
                kotlinx.coroutines.internal.k kVar = (kotlinx.coroutines.internal.k) obj;
                Object objJ = kVar.j();
                if (objJ != kotlinx.coroutines.internal.k.f5164h) {
                    return (Runnable) objJ;
                }
                androidx.concurrent.futures.a.a(f603y, this, obj, kVar.i());
            } else {
                if (obj == AbstractC0118e0.f614b) {
                    return null;
                }
                if (androidx.concurrent.futures.a.a(f603y, this, obj, null)) {
                    return (Runnable) obj;
                }
            }
        }
    }

    private final boolean Y(Runnable runnable) {
        while (true) {
            Object obj = this._queue;
            if (a0()) {
                return false;
            }
            if (obj == null) {
                if (androidx.concurrent.futures.a.a(f603y, this, null, runnable)) {
                    return true;
                }
            } else if (obj instanceof kotlinx.coroutines.internal.k) {
                kotlinx.coroutines.internal.k kVar = (kotlinx.coroutines.internal.k) obj;
                int iA = kVar.a(runnable);
                if (iA == 0) {
                    return true;
                }
                if (iA == 1) {
                    androidx.concurrent.futures.a.a(f603y, this, obj, kVar.i());
                } else if (iA == 2) {
                    return false;
                }
            } else {
                if (obj == AbstractC0118e0.f614b) {
                    return false;
                }
                kotlinx.coroutines.internal.k kVar2 = new kotlinx.coroutines.internal.k(8, true);
                kVar2.a((Runnable) obj);
                kVar2.a(runnable);
                if (androidx.concurrent.futures.a.a(f603y, this, obj, kVar2)) {
                    return true;
                }
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* JADX WARN: Type inference failed for: r0v0, types: [boolean, int] */
    public final boolean a0() {
        return this._isCompleted;
    }

    private final void e0() {
        AbstractC0113c.a();
        long jNanoTime = System.nanoTime();
        while (true) {
            c cVar = (c) this._delayed;
            b bVar = cVar == null ? null : (b) cVar.i();
            if (bVar == null) {
                return;
            } else {
                Q(jNanoTime, bVar);
            }
        }
    }

    private final int h0(long j2, b bVar) {
        if (a0()) {
            return 1;
        }
        c cVar = (c) this._delayed;
        if (cVar == null) {
            androidx.concurrent.futures.a.a(f602H, this, null, new c(j2));
            Object obj = this._delayed;
            kotlin.jvm.internal.l.b(obj);
            cVar = (c) obj;
        }
        return bVar.g(j2, cVar, this);
    }

    private final void i0(boolean z2) {
        this._isCompleted = z2 ? 1 : 0;
    }

    private final boolean j0(b bVar) {
        c cVar = (c) this._delayed;
        return (cVar == null ? null : (b) cVar.e()) == bVar;
    }

    @Override // F1.AbstractC0110a0
    protected long D() {
        if (super.D() == 0) {
            return 0L;
        }
        Object obj = this._queue;
        if (obj != null) {
            if (!(obj instanceof kotlinx.coroutines.internal.k)) {
                if (obj == AbstractC0118e0.f614b) {
                    return LocationRequestCompat.PASSIVE_INTERVAL;
                }
                return 0L;
            }
            if (!((kotlinx.coroutines.internal.k) obj).g()) {
                return 0L;
            }
        }
        c cVar = (c) this._delayed;
        b bVar = cVar == null ? null : (b) cVar.e();
        if (bVar == null) {
            return LocationRequestCompat.PASSIVE_INTERVAL;
        }
        long j2 = bVar.f606b;
        AbstractC0113c.a();
        return kotlin.ranges.m.c(j2 - System.nanoTime(), 0L);
    }

    @Override // F1.AbstractC0110a0
    public long K() {
        kotlinx.coroutines.internal.x xVarH;
        if (L()) {
            return 0L;
        }
        c cVar = (c) this._delayed;
        if (cVar != null && !cVar.d()) {
            AbstractC0113c.a();
            long jNanoTime = System.nanoTime();
            do {
                synchronized (cVar) {
                    try {
                        kotlinx.coroutines.internal.x xVarB = cVar.b();
                        if (xVarB != null) {
                            b bVar = (b) xVarB;
                            xVarH = bVar.h(jNanoTime) ? Y(bVar) : false ? cVar.h(0) : null;
                        }
                    } catch (Throwable th) {
                        throw th;
                    }
                }
            } while (((b) xVarH) != null);
        }
        Runnable runnableV = V();
        if (runnableV == null) {
            return D();
        }
        runnableV.run();
        return 0L;
    }

    @Override // F1.AbstractC0110a0
    protected void O() {
        G0.f579a.c();
        i0(true);
        U();
        while (K() <= 0) {
        }
        e0();
    }

    public final void X(Runnable runnable) {
        if (Y(runnable)) {
            R();
        } else {
            M.f587I.X(runnable);
        }
    }

    protected boolean c0() {
        if (!I()) {
            return false;
        }
        c cVar = (c) this._delayed;
        if (cVar != null && !cVar.d()) {
            return false;
        }
        Object obj = this._queue;
        if (obj != null) {
            if (obj instanceof kotlinx.coroutines.internal.k) {
                return ((kotlinx.coroutines.internal.k) obj).g();
            }
            if (obj != AbstractC0118e0.f614b) {
                return false;
            }
        }
        return true;
    }

    protected final void f0() {
        this._queue = null;
        this._delayed = null;
    }

    public final void g0(long j2, b bVar) {
        int iH0 = h0(j2, bVar);
        if (iH0 == 0) {
            if (j0(bVar)) {
                R();
            }
        } else if (iH0 == 1) {
            Q(j2, bVar);
        } else if (iH0 != 2) {
            throw new IllegalStateException("unexpected result");
        }
    }

    @Override // F1.Q
    public void l(long j2, InterfaceC0131l interfaceC0131l) {
        long jC = AbstractC0118e0.c(j2);
        if (jC < 4611686018427387903L) {
            AbstractC0113c.a();
            long jNanoTime = System.nanoTime();
            a aVar = new a(jC + jNanoTime, interfaceC0131l);
            AbstractC0133n.a(interfaceC0131l, aVar);
            g0(jNanoTime, aVar);
        }
    }

    @Override // F1.E
    public final void u(q1.g gVar, Runnable runnable) {
        X(runnable);
    }
}
