package 㴹.K.Ԕ.ⁱ;

import io.reactivex.internal.disposables.EmptyDisposable;
import io.reactivex.internal.schedulers.RxThreadFactory;
import java.util.Iterator;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import 㴹.K.AbstractC2508;
import 㴹.K.㑃.AbstractC2514;
import 㴹.K.㑃.C2515;

/* renamed from: 㴹.K.Ԕ.ⁱ.ῲ  reason: contains not printable characters */
/* compiled from: IoScheduler */
public final class C2467 extends AbstractC2508 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public static final RxThreadFactory f8418;

    /* renamed from: ඓ  reason: contains not printable characters */
    public static final TimeUnit f8419 = TimeUnit.SECONDS;

    /* renamed from: ⁱ  reason: contains not printable characters */
    public static final RunnableC2470 f8420 = new RunnableC2470(0, null, f8418);

    /* renamed from: 㴹  reason: contains not printable characters */
    public static final C2468 f8421 = new C2468(new RxThreadFactory("RxCachedThreadSchedulerShutdown"));

    /* renamed from: 㸾  reason: contains not printable characters */
    public static final RxThreadFactory f8422;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final AtomicReference<RunnableC2470> f8423 = new AtomicReference<>(f8420);

    /* renamed from: K  reason: contains not printable characters */
    public final ThreadFactory f8424 = f8418;

    /* renamed from: 㴹.K.Ԕ.ⁱ.ῲ$ʬ  reason: contains not printable characters */
    /* compiled from: IoScheduler */
    public static final class C2468 extends C2479 {

        /* renamed from: 㸾  reason: contains not printable characters */
        public long f8425 = 0;

        public C2468(ThreadFactory threadFactory) {
            super(threadFactory);
        }
    }

    /* renamed from: 㴹.K.Ԕ.ⁱ.ῲ$ῲ  reason: contains not printable characters */
    /* compiled from: IoScheduler */
    public static final class C2469 extends AbstractC2508.AbstractC2509 {

        /* renamed from: ʬ  reason: contains not printable characters */
        public final RunnableC2470 f8426;

        /* renamed from: ඓ  reason: contains not printable characters */
        public final AtomicBoolean f8427 = new AtomicBoolean();

        /* renamed from: ῲ  reason: contains not printable characters */
        public final C2515 f8428;

        /* renamed from: 㸾  reason: contains not printable characters */
        public final C2468 f8429;

        public C2469(RunnableC2470 k) {
            C2468 r0;
            this.f8426 = k;
            this.f8428 = new C2515();
            if (!k.f8435.f8515) {
                while (true) {
                    if (k.f8430.isEmpty()) {
                        r0 = new C2468(k.f8433);
                        k.f8435.m6564(r0);
                        break;
                    }
                    r0 = k.f8430.poll();
                    if (r0 != null) {
                        break;
                    }
                }
            } else {
                r0 = C2467.f8421;
            }
            this.f8429 = r0;
        }

        @Override // 㴹.K.㑃.AbstractC2514
        public void dispose() {
            if (this.f8427.compareAndSet(false, true)) {
                this.f8428.dispose();
                RunnableC2470 k = this.f8426;
                C2468 r1 = this.f8429;
                r1.f8425 = k.m6507() + k.f8432;
                k.f8430.offer(r1);
            }
        }

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

        @Override // 㴹.K.AbstractC2508.AbstractC2509
        /* renamed from: K  reason: contains not printable characters */
        public AbstractC2514 m6505(Runnable runnable, long j, TimeUnit timeUnit) {
            if (this.f8428.f8515) {
                return EmptyDisposable.INSTANCE;
            }
            return this.f8429.m6519(runnable, j, timeUnit, this.f8428);
        }
    }

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

        /* renamed from: ʬ  reason: contains not printable characters */
        public final ConcurrentLinkedQueue<C2468> f8430;

        /* renamed from: ඓ  reason: contains not printable characters */
        public final ScheduledExecutorService f8431;

        /* renamed from: ῲ  reason: contains not printable characters */
        public final long f8432;

        /* renamed from: ⁱ  reason: contains not printable characters */
        public final ThreadFactory f8433;

        /* renamed from: 㴹  reason: contains not printable characters */
        public final Future<?> f8434;

        /* renamed from: 㸾  reason: contains not printable characters */
        public final C2515 f8435;

        public RunnableC2470(long j, TimeUnit timeUnit, ThreadFactory threadFactory) {
            ScheduledFuture<?> scheduledFuture;
            this.f8432 = timeUnit != null ? timeUnit.toNanos(j) : 0;
            this.f8430 = new ConcurrentLinkedQueue<>();
            this.f8435 = new C2515();
            this.f8433 = threadFactory;
            ScheduledExecutorService scheduledExecutorService = null;
            if (timeUnit != null) {
                scheduledExecutorService = Executors.newScheduledThreadPool(1, C2467.f8422);
                long j2 = this.f8432;
                scheduledFuture = scheduledExecutorService.scheduleWithFixedDelay(this, j2, j2, TimeUnit.NANOSECONDS);
            } else {
                scheduledFuture = null;
            }
            this.f8431 = scheduledExecutorService;
            this.f8434 = scheduledFuture;
        }

        public void run() {
            if (!this.f8430.isEmpty()) {
                long r0 = m6507();
                Iterator<C2468> it2 = this.f8430.iterator();
                while (it2.hasNext()) {
                    C2468 next = it2.next();
                    if (next.f8425 > r0) {
                        return;
                    }
                    if (this.f8430.remove(next)) {
                        this.f8435.m6565(next);
                    }
                }
            }
        }

        /* renamed from: ῲ  reason: contains not printable characters */
        public void m6506() {
            this.f8435.dispose();
            Future<?> future = this.f8434;
            if (future != null) {
                future.cancel(true);
            }
            ScheduledExecutorService scheduledExecutorService = this.f8431;
            if (scheduledExecutorService != null) {
                scheduledExecutorService.shutdownNow();
            }
        }

        /* renamed from: K  reason: contains not printable characters */
        public long m6507() {
            return System.nanoTime();
        }
    }

    static {
        f8421.dispose();
        int max = Math.max(1, Math.min(10, Integer.getInteger("rx2.io-priority", 5).intValue()));
        f8418 = new RxThreadFactory("RxCachedThreadScheduler", max);
        f8422 = new RxThreadFactory("RxCachedWorkerPoolEvictor", max);
        RunnableC2470 k = f8420;
        k.f8435.dispose();
        Future<?> future = k.f8434;
        if (future != null) {
            future.cancel(true);
        }
        ScheduledExecutorService scheduledExecutorService = k.f8431;
        if (scheduledExecutorService != null) {
            scheduledExecutorService.shutdownNow();
        }
    }

    public C2467() {
        RunnableC2470 k = new RunnableC2470(60, f8419, this.f8424);
        if (!this.f8423.compareAndSet(f8420, k)) {
            k.m6506();
        }
    }

    @Override // 㴹.K.AbstractC2508
    /* renamed from: K  reason: contains not printable characters */
    public AbstractC2508.AbstractC2509 m6504() {
        return new C2469(this.f8423.get());
    }
}
