package kotlinx.coroutines;

import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import org.jetbrains.annotations.Nullable;

/* JADX INFO: loaded from: classes.dex */
public abstract class n0 implements Runnable, Comparable, j0 {

    @Nullable
    private volatile Object _heap;

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public int f29512b = -1;

    public n0(long j10) {
        this.f29511a = j10;
    }

    public final kotlinx.coroutines.internal.y a() {
        Object obj = this._heap;
        if (obj instanceof kotlinx.coroutines.internal.y) {
            return (kotlinx.coroutines.internal.y) obj;
        }
        return null;
    }

    public final int b(long j10, o0 o0Var, p0 p0Var) {
        synchronized (this) {
            if (this._heap == y.f29583j) {
                return 2;
            }
            synchronized (o0Var) {
                try {
                    n0[] n0VarArr = o0Var.f29499a;
                    n0 n0Var = n0VarArr != null ? n0VarArr[0] : null;
                    AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = p0.f29519g;
                    p0Var.getClass();
                    if (p0.f29521i.get(p0Var) != 0) {
                        return 1;
                    }
                    if (n0Var == null) {
                        o0Var.f29513c = j10;
                    } else {
                        long j11 = n0Var.f29511a;
                        if (j11 - j10 < 0) {
                            j10 = j11;
                        }
                        if (j10 - o0Var.f29513c > 0) {
                            o0Var.f29513c = j10;
                        }
                    }
                    long j12 = this.f29511a;
                    long j13 = o0Var.f29513c;
                    if (j12 - j13 < 0) {
                        this.f29511a = j13;
                    }
                    o0Var.a(this);
                    return 0;
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
    }

    @Override // java.lang.Comparable
    public final int compareTo(Object obj) {
        long j10 = this.f29511a - ((n0) obj).f29511a;
        if (j10 > 0) {
            return 1;
        }
        return j10 < 0 ? -1 : 0;
    }

    public final void d(o0 o0Var) {
        if (this._heap == y.f29583j) {
            throw new IllegalArgumentException("Failed requirement.".toString());
        }
        this._heap = o0Var;
    }

    @Override // kotlinx.coroutines.j0
    public final void dispose() {
        synchronized (this) {
            try {
                Object obj = this._heap;
                la.e eVar = y.f29583j;
                if (obj == eVar) {
                    return;
                }
                o0 o0Var = obj instanceof o0 ? (o0) obj : null;
                if (o0Var != null) {
                    synchronized (o0Var) {
                        if (a() != null) {
                            o0Var.b(this.f29512b);
                        }
                    }
                }
                this._heap = eVar;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

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