package 㴹.K.Ԕ.ⁱ;

import io.reactivex.disposables.RunnableDisposable;
import io.reactivex.internal.disposables.EmptyDisposable;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import ඓ.ⁱ.K.ඓ.C1252;
import 㴹.K.AbstractC2508;
import 㴹.K.Ԕ.ῲ.C2456;
import 㴹.K.㑃.AbstractC2514;

/* renamed from: 㴹.K.Ԕ.ⁱ.㿎  reason: contains not printable characters */
/* compiled from: TrampolineScheduler */
public final class C2480 extends AbstractC2508 {

    /* renamed from: K  reason: contains not printable characters */
    public static final C2480 f8461 = new C2480();

    /* renamed from: 㴹.K.Ԕ.ⁱ.㿎$ʬ  reason: contains not printable characters */
    /* compiled from: TrampolineScheduler */
    public static final class C2481 extends AbstractC2508.AbstractC2509 implements AbstractC2514 {

        /* renamed from: ʬ  reason: contains not printable characters */
        public final AtomicInteger f8462 = new AtomicInteger();

        /* renamed from: ඓ  reason: contains not printable characters */
        public volatile boolean f8463;

        /* renamed from: ῲ  reason: contains not printable characters */
        public final PriorityBlockingQueue<C2483> f8464 = new PriorityBlockingQueue<>();

        /* renamed from: 㸾  reason: contains not printable characters */
        public final AtomicInteger f8465 = new AtomicInteger();

        /* renamed from: 㴹.K.Ԕ.ⁱ.㿎$ʬ$K  reason: contains not printable characters */
        /* compiled from: TrampolineScheduler */
        public final class RunnableC2482 implements Runnable {

            /* renamed from: ῲ  reason: contains not printable characters */
            public final C2483 f8467;

            public RunnableC2482(C2483 r2) {
                this.f8467 = r2;
            }

            public void run() {
                C2483 r0 = this.f8467;
                r0.f8469 = true;
                C2481.this.f8464.remove(r0);
            }
        }

        @Override // 㴹.K.㑃.AbstractC2514
        public void dispose() {
            this.f8463 = true;
        }

        @Override // 㴹.K.㑃.AbstractC2514
        public boolean isDisposed() {
            return this.f8463;
        }

        @Override // 㴹.K.AbstractC2508.AbstractC2509
        /* renamed from: K  reason: contains not printable characters */
        public AbstractC2514 m6525(Runnable runnable) {
            return m6526(runnable, m6553(TimeUnit.MILLISECONDS));
        }

        @Override // 㴹.K.AbstractC2508.AbstractC2509
        /* renamed from: K  reason: contains not printable characters */
        public AbstractC2514 m6527(Runnable runnable, long j, TimeUnit timeUnit) {
            long millis = timeUnit.toMillis(j) + m6553(TimeUnit.MILLISECONDS);
            return m6526(new RunnableC2484(runnable, this, millis), millis);
        }

        /* renamed from: K  reason: contains not printable characters */
        public AbstractC2514 m6526(Runnable runnable, long j) {
            if (this.f8463) {
                return EmptyDisposable.INSTANCE;
            }
            C2483 r0 = new C2483(runnable, Long.valueOf(j), this.f8465.incrementAndGet());
            this.f8464.add(r0);
            if (this.f8462.getAndIncrement() == 0) {
                int i = 1;
                while (!this.f8463) {
                    C2483 poll = this.f8464.poll();
                    if (poll == null) {
                        i = this.f8462.addAndGet(-i);
                        if (i == 0) {
                            return EmptyDisposable.INSTANCE;
                        }
                    } else if (!poll.f8469) {
                        poll.f8470.run();
                    }
                }
                this.f8464.clear();
                return EmptyDisposable.INSTANCE;
            }
            RunnableC2482 k = new RunnableC2482(r0);
            C2456.m6500(k, "run is null");
            return new RunnableDisposable(k);
        }
    }

    /* renamed from: 㴹.K.Ԕ.ⁱ.㿎$ῲ  reason: contains not printable characters */
    /* compiled from: TrampolineScheduler */
    public static final class C2483 implements Comparable<C2483> {

        /* renamed from: ʬ  reason: contains not printable characters */
        public final long f8468;

        /* renamed from: ඓ  reason: contains not printable characters */
        public volatile boolean f8469;

        /* renamed from: ῲ  reason: contains not printable characters */
        public final Runnable f8470;

        /* renamed from: 㸾  reason: contains not printable characters */
        public final int f8471;

        public C2483(Runnable runnable, Long l, int i) {
            this.f8470 = runnable;
            this.f8468 = l.longValue();
            this.f8471 = i;
        }

        /* JADX DEBUG: Method arguments types fixed to match base method, original types: [java.lang.Object] */
        @Override // java.lang.Comparable
        public int compareTo(C2483 r9) {
            C2483 r92 = r9;
            int i = (this.f8468 > r92.f8468 ? 1 : (this.f8468 == r92.f8468 ? 0 : -1));
            int i2 = i < 0 ? -1 : i > 0 ? 1 : 0;
            if (i2 != 0) {
                return i2;
            }
            int i3 = this.f8471;
            int i4 = r92.f8471;
            if (i3 < i4) {
                return -1;
            }
            return i3 > i4 ? 1 : 0;
        }
    }

    /* renamed from: 㴹.K.Ԕ.ⁱ.㿎$K  reason: contains not printable characters */
    /* compiled from: TrampolineScheduler */
    public static final class RunnableC2484 implements Runnable {

        /* renamed from: ʬ  reason: contains not printable characters */
        public final C2481 f8472;

        /* renamed from: ῲ  reason: contains not printable characters */
        public final Runnable f8473;

        /* renamed from: 㸾  reason: contains not printable characters */
        public final long f8474;

        public RunnableC2484(Runnable runnable, C2481 r2, long j) {
            this.f8473 = runnable;
            this.f8472 = r2;
            this.f8474 = j;
        }

        public void run() {
            if (!this.f8472.f8463) {
                long r0 = this.f8472.m6553(TimeUnit.MILLISECONDS);
                long j = this.f8474;
                if (j > r0) {
                    long j2 = j - r0;
                    if (j2 > 0) {
                        try {
                            Thread.sleep(j2);
                        } catch (InterruptedException e) {
                            Thread.currentThread().interrupt();
                            C1252.m3349(e);
                            return;
                        }
                    }
                }
                if (!this.f8472.f8463) {
                    this.f8473.run();
                }
            }
        }
    }

    @Override // 㴹.K.AbstractC2508
    /* renamed from: K  reason: contains not printable characters */
    public AbstractC2508.AbstractC2509 m6522() {
        return new C2481();
    }

    @Override // 㴹.K.AbstractC2508
    /* renamed from: K  reason: contains not printable characters */
    public AbstractC2514 m6523(Runnable runnable) {
        runnable.run();
        return EmptyDisposable.INSTANCE;
    }

    @Override // 㴹.K.AbstractC2508
    /* renamed from: K  reason: contains not printable characters */
    public AbstractC2514 m6524(Runnable runnable, long j, TimeUnit timeUnit) {
        try {
            timeUnit.sleep(j);
            runnable.run();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            C1252.m3349(e);
        }
        return EmptyDisposable.INSTANCE;
    }
}
