package defpackage;

import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import java.util.concurrent.locks.LockSupport;
import sun.misc.Unsafe;

/* renamed from: ᵙˎᵶᵷ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public abstract class AbstractC2584 extends AbstractC0685 implements InterfaceC5297 {

    /* renamed from: ˀᵗᵝᵭ, reason: contains not printable characters */
    public static final /* synthetic */ AtomicIntegerFieldUpdater f10022;

    /* renamed from: ˑᵥˁ, reason: contains not printable characters */
    public static final /* synthetic */ long f10023;

    /* renamed from: ᵡˎ, reason: contains not printable characters */
    public static final /* synthetic */ long f10024;

    /* renamed from: ᵡⁱᵥ, reason: contains not printable characters */
    public static final /* synthetic */ AtomicReferenceFieldUpdater f10025;

    /* renamed from: ᵤᵙᵷ, reason: contains not printable characters */
    public static final /* synthetic */ AtomicReferenceFieldUpdater f10026 = AtomicReferenceFieldUpdater.newUpdater(AbstractC2584.class, Object.class, "_queue$volatile");
    private volatile /* synthetic */ Object _delayed$volatile;
    private volatile /* synthetic */ int _isCompleted$volatile;
    private volatile /* synthetic */ Object _queue$volatile;

    static {
        Unsafe unsafe = AbstractC3747.f13986;
        f10023 = unsafe.objectFieldOffset(AbstractC2584.class.getDeclaredField("_queue$volatile"));
        f10025 = AtomicReferenceFieldUpdater.newUpdater(AbstractC2584.class, Object.class, "_delayed$volatile");
        f10024 = unsafe.objectFieldOffset(AbstractC2584.class.getDeclaredField("_delayed$volatile"));
        f10022 = AtomicIntegerFieldUpdater.newUpdater(AbstractC2584.class, "_isCompleted$volatile");
    }

    @Override // defpackage.AbstractC0685
    public void shutdown() {
        AbstractC1407.f5763.set(null);
        f10022.set(this, 1);
        m6477();
        while (mo2665() <= 0) {
        }
        m6485();
    }

    /* renamed from: ʽᵢˊ, reason: contains not printable characters */
    public final void m6477() {
        AbstractC2584 abstractC2584;
        Unsafe unsafe;
        while (true) {
            f10026.getClass();
            Unsafe unsafe2 = AbstractC3747.f13986;
            long j = f10023;
            Object objectVolatile = unsafe2.getObjectVolatile(this, j);
            C0434 c0434 = AbstractC1877.f7597;
            if (objectVolatile == null) {
                while (true) {
                    Unsafe unsafe3 = AbstractC3747.f13986;
                    AbstractC2584 abstractC25842 = this;
                    abstractC2584 = abstractC25842;
                    if (unsafe3.compareAndSwapObject(abstractC25842, f10023, (Object) null, c0434)) {
                        return;
                    }
                    if (unsafe3.getObjectVolatile(abstractC2584, j) != null) {
                        break;
                    } else {
                        this = abstractC2584;
                    }
                }
            } else {
                abstractC2584 = this;
                if (objectVolatile instanceof C0807) {
                    ((C0807) objectVolatile).m2905();
                    return;
                }
                if (objectVolatile == c0434) {
                    return;
                }
                C0807 c0807 = new C0807(8, true);
                c0807.m2906((Runnable) objectVolatile);
                do {
                    unsafe = AbstractC3747.f13986;
                    if (unsafe.compareAndSwapObject(abstractC2584, f10023, objectVolatile, c0807)) {
                        return;
                    }
                } while (unsafe.getObjectVolatile(abstractC2584, j) == objectVolatile);
            }
            this = abstractC2584;
        }
    }

    /* renamed from: ʾˋˊᵽ, reason: contains not printable characters */
    public final boolean m6478(Runnable runnable) {
        Unsafe unsafe;
        Unsafe unsafe2;
        Unsafe unsafe3;
        loop0: while (true) {
            f10026.getClass();
            Unsafe unsafe4 = AbstractC3747.f13986;
            long j = f10023;
            Object objectVolatile = unsafe4.getObjectVolatile(this, j);
            if (f10022.get(this) == 1) {
                return false;
            }
            if (objectVolatile == null) {
                do {
                    unsafe = AbstractC3747.f13986;
                    if (unsafe.compareAndSwapObject(this, f10023, (Object) null, runnable)) {
                        break loop0;
                    }
                } while (unsafe.getObjectVolatile(this, j) == null);
            } else if (objectVolatile instanceof C0807) {
                C0807 c0807 = (C0807) objectVolatile;
                int iM2906 = c0807.m2906(runnable);
                if (iM2906 == 0) {
                    break;
                }
                if (iM2906 == 1) {
                    C0807 c0807M2908 = c0807.m2908();
                    do {
                        unsafe2 = AbstractC3747.f13986;
                        if (unsafe2.compareAndSwapObject(this, f10023, objectVolatile, c0807M2908)) {
                            break;
                        }
                    } while (unsafe2.getObjectVolatile(this, j) == objectVolatile);
                } else if (iM2906 == 2) {
                    return false;
                }
            } else {
                if (objectVolatile == AbstractC1877.f7597) {
                    return false;
                }
                C0807 c08072 = new C0807(8, true);
                c08072.m2906((Runnable) objectVolatile);
                c08072.m2906(runnable);
                do {
                    unsafe3 = AbstractC3747.f13986;
                    if (unsafe3.compareAndSwapObject(this, f10023, objectVolatile, c08072)) {
                        break loop0;
                    }
                } while (unsafe3.getObjectVolatile(this, j) == objectVolatile);
            }
        }
        return true;
    }

    @Override // defpackage.AbstractC2687
    /* renamed from: ʾᵻᵭٴ */
    public final void mo1226(InterfaceC2262 interfaceC2262, Runnable runnable) {
        mo2058(runnable);
    }

    /* renamed from: ʿᵘˆ */
    public void mo2058(Runnable runnable) {
        m6483();
        if (!m6478(runnable)) {
            RunnableC0457.f2516.mo2058(runnable);
            return;
        }
        Thread threadMo2061 = mo2061();
        if (Thread.currentThread() != threadMo2061) {
            LockSupport.unpark(threadMo2061);
        }
    }

    /* renamed from: ˆʕ, reason: contains not printable characters */
    public final boolean m6479(AbstractRunnableC0718 abstractRunnableC0718) {
        f10025.getClass();
        C2778 c2778 = (C2778) AbstractC3747.f13986.getObjectVolatile(this, f10024);
        if (c2778 != null) {
            synchronized (c2778) {
                AbstractRunnableC0718[] abstractRunnableC0718Arr = c2778.f6953;
                abstractRunnableC0718 = abstractRunnableC0718Arr != null ? abstractRunnableC0718Arr[0] : null;
            }
        }
        return abstractRunnableC0718 == abstractRunnableC0718;
    }

    /* renamed from: ˉᵴﹶ */
    public void mo2059(long j, AbstractRunnableC0718 abstractRunnableC0718) {
        RunnableC0457.f2516.m6481(j, abstractRunnableC0718);
    }

    @Override // defpackage.InterfaceC5297
    /* renamed from: ˊᵸˊ */
    public final void mo4037(long j, C4385 c4385) {
        long j2 = j > 0 ? j >= 9223372036854L ? Long.MAX_VALUE : 1000000 * j : 0L;
        if (j2 < 4611686018427387903L) {
            long jNanoTime = System.nanoTime();
            C2309 c2309 = new C2309(this, j2 + jNanoTime, c4385);
            m6481(jNanoTime, c2309);
            c4385.m9401(new C3033(2, c2309));
        }
    }

    /* renamed from: ᵎʾ */
    public abstract Thread mo2061();

    /* renamed from: ᵠᵪˀᵻ, reason: contains not printable characters */
    public final Runnable m6480() {
        AbstractC2584 abstractC2584;
        Unsafe unsafe;
        while (true) {
            f10026.getClass();
            Unsafe unsafe2 = AbstractC3747.f13986;
            long j = f10023;
            Object objectVolatile = unsafe2.getObjectVolatile(this, j);
            if (objectVolatile == null) {
                return null;
            }
            if (objectVolatile instanceof C0807) {
                C0807 c0807 = (C0807) objectVolatile;
                Object objM2904 = c0807.m2904();
                if (objM2904 != C0807.f3744) {
                    return (Runnable) objM2904;
                }
                C0807 c0807M2908 = c0807.m2908();
                while (true) {
                    Unsafe unsafe3 = AbstractC3747.f13986;
                    abstractC2584 = this;
                    if (!unsafe3.compareAndSwapObject(abstractC2584, f10023, objectVolatile, c0807M2908) && unsafe3.getObjectVolatile(abstractC2584, j) == objectVolatile) {
                        this = abstractC2584;
                    }
                }
            } else {
                abstractC2584 = this;
                if (objectVolatile == AbstractC1877.f7597) {
                    return null;
                }
                do {
                    unsafe = AbstractC3747.f13986;
                    if (unsafe.compareAndSwapObject(abstractC2584, f10023, objectVolatile, (Object) null)) {
                        return (Runnable) objectVolatile;
                    }
                } while (unsafe.getObjectVolatile(abstractC2584, j) == objectVolatile);
            }
            this = abstractC2584;
        }
    }

    /* renamed from: ᵡⁱᵥ */
    public InterfaceC3451 mo2062(long j, Runnable runnable, InterfaceC2262 interfaceC2262) {
        return AbstractC2451.f9569.mo2062(j, runnable, interfaceC2262);
    }

    /* renamed from: ᵦᵳˎ, reason: contains not printable characters */
    public final void m6481(long j, AbstractRunnableC0718 abstractRunnableC0718) {
        Thread threadMo2061;
        int iM6484 = m6484(j, abstractRunnableC0718);
        if (iM6484 == 0) {
            if (!m6479(abstractRunnableC0718) || Thread.currentThread() == (threadMo2061 = mo2061())) {
                return;
            }
            LockSupport.unpark(threadMo2061);
            return;
        }
        if (iM6484 == 1) {
            mo2059(j, abstractRunnableC0718);
        } else {
            if (iM6484 == 2) {
                return;
            }
            ᵹˉᵞ.ᵳٴᵶ("unexpected result");
        }
    }

    /* renamed from: ᵪᵛʿ, reason: contains not printable characters */
    public final void m6482() {
        f10026.getClass();
        Unsafe unsafe = AbstractC3747.f13986;
        unsafe.putObjectVolatile(this, f10023, (Object) null);
        f10025.getClass();
        unsafe.putObjectVolatile(this, f10024, (Object) null);
    }

    /* renamed from: ᵰʖʢ, reason: contains not printable characters */
    public final void m6483() {
        AbstractRunnableC0718 abstractRunnableC0718M4959;
        f10025.getClass();
        C2778 c2778 = (C2778) AbstractC3747.f13986.getObjectVolatile(this, f10024);
        if (c2778 == null || C1742.f6952.get(c2778) == 0) {
            return;
        }
        long jNanoTime = System.nanoTime();
        do {
            synchronized (c2778) {
                try {
                    AbstractRunnableC0718[] abstractRunnableC0718Arr = c2778.f6953;
                    abstractRunnableC0718M4959 = null;
                    AbstractRunnableC0718 abstractRunnableC0718 = abstractRunnableC0718Arr != null ? abstractRunnableC0718Arr[0] : null;
                    if (abstractRunnableC0718 != null) {
                        if (jNanoTime - abstractRunnableC0718.f3456 >= 0 ? m6478(abstractRunnableC0718) : false) {
                            abstractRunnableC0718M4959 = c2778.m4959(0);
                        }
                    }
                } catch (Throwable th) {
                    throw th;
                }
            }
        } while (abstractRunnableC0718M4959 != null);
    }

    @Override // defpackage.AbstractC0685
    /* renamed from: ᵲᵟ */
    public final long mo2665() {
        if (m2664()) {
            return 0L;
        }
        m6483();
        Runnable runnableM6480 = m6480();
        if (runnableM6480 == null) {
            return m6487();
        }
        runnableM6480.run();
        return 0L;
    }

    /* renamed from: ᵳᵮᵸ, reason: contains not printable characters */
    public final int m6484(long j, AbstractRunnableC0718 abstractRunnableC0718) {
        AbstractC2584 abstractC2584;
        Unsafe unsafe;
        if (f10022.get(this) == 1) {
            return 1;
        }
        f10025.getClass();
        Unsafe unsafe2 = AbstractC3747.f13986;
        long j2 = f10024;
        C2778 c2778 = (C2778) unsafe2.getObjectVolatile(this, j2);
        if (c2778 == null) {
            C2778 c27782 = new C2778();
            c27782.f10714 = j;
            while (true) {
                unsafe = AbstractC3747.f13986;
                abstractC2584 = this;
                if (unsafe.compareAndSwapObject(abstractC2584, f10024, (Object) null, c27782) || unsafe.getObjectVolatile(abstractC2584, j2) != null) {
                    break;
                }
                this = abstractC2584;
            }
            c2778 = (C2778) unsafe.getObjectVolatile(abstractC2584, j2);
        } else {
            abstractC2584 = this;
        }
        return abstractRunnableC0718.m2721(j, c2778, abstractC2584);
    }

    /* renamed from: ᵴᵯᵴⁱ, reason: contains not printable characters */
    public final void m6485() {
        AbstractRunnableC0718 abstractRunnableC0718M4959;
        long jNanoTime = System.nanoTime();
        while (true) {
            f10025.getClass();
            C2778 c2778 = (C2778) AbstractC3747.f13986.getObjectVolatile(this, f10024);
            if (c2778 == null) {
                return;
            }
            synchronized (c2778) {
                abstractRunnableC0718M4959 = C1742.f6952.get(c2778) > 0 ? c2778.m4959(0) : null;
            }
            if (abstractRunnableC0718M4959 == null) {
                return;
            } else {
                mo2059(jNanoTime, abstractRunnableC0718M4959);
            }
        }
    }

    /* renamed from: ᵷᵦﹳ, reason: contains not printable characters */
    public final boolean m6486() {
        C2366 c2366 = this.f3353;
        if (c2366 != null ? c2366.isEmpty() : true) {
            f10025.getClass();
            Unsafe unsafe = AbstractC3747.f13986;
            C2778 c2778 = (C2778) unsafe.getObjectVolatile(this, f10024);
            if (c2778 != null && C1742.f6952.get(c2778) != 0) {
                return false;
            }
            f10026.getClass();
            Object objectVolatile = unsafe.getObjectVolatile(this, f10023);
            if (objectVolatile != null) {
                if (objectVolatile instanceof C0807) {
                    long j = C0807.f3745.get((C0807) objectVolatile);
                    return ((int) (1073741823 & j)) == ((int) ((j & 1152921503533105152L) >> 30));
                }
                if (objectVolatile == AbstractC1877.f7597) {
                }
            }
            return true;
        }
        return false;
    }

    /* renamed from: ᵺᵜᵰ, reason: contains not printable characters */
    public final long m6487() {
        AbstractRunnableC0718 abstractRunnableC0718;
        C2366 c2366 = this.f3353;
        if (((c2366 == null || c2366.isEmpty()) ? Long.MAX_VALUE : 0L) != 0) {
            f10026.getClass();
            Unsafe unsafe = AbstractC3747.f13986;
            Object objectVolatile = unsafe.getObjectVolatile(this, f10023);
            if (objectVolatile != null) {
                if (objectVolatile instanceof C0807) {
                    long j = C0807.f3745.get((C0807) objectVolatile);
                    if (((int) (1073741823 & j)) != ((int) ((j & 1152921503533105152L) >> 30))) {
                        return 0L;
                    }
                } else if (objectVolatile == AbstractC1877.f7597) {
                    return Long.MAX_VALUE;
                }
            }
            f10025.getClass();
            C2778 c2778 = (C2778) unsafe.getObjectVolatile(this, f10024);
            if (c2778 != null) {
                synchronized (c2778) {
                    AbstractRunnableC0718[] abstractRunnableC0718Arr = c2778.f6953;
                    abstractRunnableC0718 = abstractRunnableC0718Arr != null ? abstractRunnableC0718Arr[0] : null;
                }
                if (abstractRunnableC0718 != null) {
                    long jNanoTime = abstractRunnableC0718.f3456 - System.nanoTime();
                    if (jNanoTime >= 0) {
                        return jNanoTime;
                    }
                }
            }
            return Long.MAX_VALUE;
        }
        return 0L;
    }
}
