package V4;

import I2.C0317a;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/* JADX INFO: loaded from: classes3.dex */
public abstract class V implements Runnable, Comparable, P {
    private volatile Object _heap;

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

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

    public V(long j4) {
        this.f8269a = j4;
    }

    public final int b(long j4, W w6, X x6) {
        synchronized (this) {
            if (this._heap == E.f8231b) {
                return 2;
            }
            synchronized (w6) {
                try {
                    V[] vArr = w6.f10854a;
                    V v3 = vArr != null ? vArr[0] : null;
                    AtomicReferenceFieldUpdater atomicReferenceFieldUpdater = X.f8272f;
                    x6.getClass();
                    if (X.f8274k.get(x6) != 0) {
                        return 1;
                    }
                    if (v3 == null) {
                        w6.f8271c = j4;
                    } else {
                        long j6 = v3.f8269a;
                        if (j6 - j4 < 0) {
                            j4 = j6;
                        }
                        if (j4 - w6.f8271c > 0) {
                            w6.f8271c = j4;
                        }
                    }
                    long j7 = this.f8269a;
                    long j8 = w6.f8271c;
                    if (j7 - j8 < 0) {
                        this.f8269a = j8;
                    }
                    w6.a(this);
                    return 0;
                } catch (Throwable th) {
                    throw th;
                }
            }
        }
    }

    public final void c(W w6) {
        if (this._heap == E.f8231b) {
            throw new IllegalArgumentException("Failed requirement.");
        }
        this._heap = w6;
    }

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

    @Override // V4.P
    public final void dispose() {
        synchronized (this) {
            try {
                Object obj = this._heap;
                C0317a c0317a = E.f8231b;
                if (obj == c0317a) {
                    return;
                }
                W w6 = obj instanceof W ? (W) obj : null;
                if (w6 != null) {
                    synchronized (w6) {
                        Object obj2 = this._heap;
                        if ((obj2 instanceof a5.u ? (a5.u) obj2 : null) != null) {
                            w6.b(this.f8270b);
                        }
                    }
                }
                this._heap = c0317a;
            } catch (Throwable th) {
                throw th;
            }
        }
    }

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