package f.a.n.g;

import f.a.g;
import java.util.concurrent.ThreadFactory;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;

/* JADX INFO: compiled from: ComputationScheduler.java */
/* JADX INFO: loaded from: classes.dex */
public final class b extends f.a.g {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    static final C0053b f873d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    static final g f874e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    static final int f875f = e(Runtime.getRuntime().availableProcessors(), Integer.getInteger("rx2.computation-threads", 0).intValue());

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    static final c f876g;
    final ThreadFactory b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    final AtomicReference<C0053b> f877c;

    /* JADX INFO: compiled from: ComputationScheduler.java */
    static final class a extends g.c {
        private final f.a.n.a.d b = new f.a.n.a.d();

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        private final f.a.k.a f878e = new f.a.k.a();

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        private final f.a.n.a.d f879f;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        private final c f880g;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        volatile boolean f881h;

        a(c cVar) {
            this.f880g = cVar;
            f.a.n.a.d dVar = new f.a.n.a.d();
            this.f879f = dVar;
            dVar.c(this.b);
            this.f879f.c(this.f878e);
        }

        @Override // f.a.g.c
        public f.a.k.b b(Runnable runnable) {
            return this.f881h ? f.a.n.a.c.INSTANCE : this.f880g.e(runnable, 0L, TimeUnit.MILLISECONDS, this.b);
        }

        @Override // f.a.g.c
        public f.a.k.b c(Runnable runnable, long j2, TimeUnit timeUnit) {
            return this.f881h ? f.a.n.a.c.INSTANCE : this.f880g.e(runnable, j2, timeUnit, this.f878e);
        }

        @Override // f.a.k.b
        public void dispose() {
            if (this.f881h) {
                return;
            }
            this.f881h = true;
            this.f879f.dispose();
        }
    }

    /* JADX INFO: renamed from: f.a.n.g.b$b, reason: collision with other inner class name */
    /* JADX INFO: compiled from: ComputationScheduler.java */
    static final class C0053b {
        final int a;
        final c[] b;

        /* JADX INFO: renamed from: c, reason: collision with root package name */
        long f882c;

        C0053b(int i2, ThreadFactory threadFactory) {
            this.a = i2;
            this.b = new c[i2];
            for (int i3 = 0; i3 < i2; i3++) {
                this.b[i3] = new c(threadFactory);
            }
        }

        public c a() {
            int i2 = this.a;
            if (i2 == 0) {
                return b.f876g;
            }
            c[] cVarArr = this.b;
            long j2 = this.f882c;
            this.f882c = 1 + j2;
            return cVarArr[(int) (j2 % ((long) i2))];
        }

        public void b() {
            for (c cVar : this.b) {
                cVar.dispose();
            }
        }
    }

    /* JADX INFO: compiled from: ComputationScheduler.java */
    static final class c extends f {
        c(ThreadFactory threadFactory) {
            super(threadFactory);
        }
    }

    static {
        c cVar = new c(new g("RxComputationShutdown"));
        f876g = cVar;
        cVar.dispose();
        g gVar = new g("RxComputationThreadPool", Math.max(1, Math.min(10, Integer.getInteger("rx2.computation-priority", 5).intValue())), true);
        f874e = gVar;
        C0053b c0053b = new C0053b(0, gVar);
        f873d = c0053b;
        c0053b.b();
    }

    public b() {
        this(f874e);
    }

    static int e(int i2, int i3) {
        return (i3 <= 0 || i3 > i2) ? i2 : i3;
    }

    @Override // f.a.g
    public g.c a() {
        return new a(this.f877c.get().a());
    }

    @Override // f.a.g
    public f.a.k.b c(Runnable runnable, long j2, TimeUnit timeUnit) {
        return this.f877c.get().a().f(runnable, j2, timeUnit);
    }

    @Override // f.a.g
    public f.a.k.b d(Runnable runnable, long j2, long j3, TimeUnit timeUnit) {
        return this.f877c.get().a().g(runnable, j2, j3, timeUnit);
    }

    public void f() {
        C0053b c0053b = new C0053b(f875f, this.b);
        if (this.f877c.compareAndSet(f873d, c0053b)) {
            return;
        }
        c0053b.b();
    }

    public b(ThreadFactory threadFactory) {
        this.b = threadFactory;
        this.f877c = new AtomicReference<>(f873d);
        f();
    }
}
