package i.a;

import java.util.concurrent.TimeUnit;

/* JADX INFO: compiled from: Scheduler.java */
/* JADX INFO: loaded from: classes.dex */
public abstract class h {
    static final long a = TimeUnit.MINUTES.toNanos(Long.getLong("rx2.scheduler.drift-tolerance", 15).longValue());

    /* JADX INFO: compiled from: Scheduler.java */
    static final class a implements i.a.k.b, Runnable {
        final Runnable b;
        final c d;
        Thread e;

        a(Runnable runnable, c cVar) {
            this.b = runnable;
            this.d = cVar;
        }

        @Override // i.a.k.b
        public void dispose() {
            if (this.e == Thread.currentThread()) {
                c cVar = this.d;
                if (cVar instanceof i.a.n.g.f) {
                    ((i.a.n.g.f) cVar).h();
                    return;
                }
            }
            this.d.dispose();
        }

        @Override // i.a.k.b
        public boolean isDisposed() {
            return this.d.isDisposed();
        }

        @Override // java.lang.Runnable
        public void run() {
            this.e = Thread.currentThread();
            try {
                this.b.run();
            } finally {
                dispose();
                this.e = null;
            }
        }
    }

    /* JADX INFO: compiled from: Scheduler.java */
    static class b implements i.a.k.b, Runnable {
        final Runnable b;
        final c d;
        volatile boolean e;

        b(Runnable runnable, c cVar) {
            this.b = runnable;
            this.d = cVar;
        }

        @Override // i.a.k.b
        public void dispose() {
            this.e = true;
            this.d.dispose();
        }

        @Override // i.a.k.b
        public boolean isDisposed() {
            return this.e;
        }

        @Override // java.lang.Runnable
        public void run() {
            if (this.e) {
                return;
            }
            try {
                this.b.run();
            } catch (Throwable th) {
                i.a.l.b.b(th);
                this.d.dispose();
                throw i.a.n.h.c.c(th);
            }
        }
    }

    /* JADX INFO: compiled from: Scheduler.java */
    public static abstract class c implements i.a.k.b {

        /* JADX INFO: compiled from: Scheduler.java */
        final class a implements Runnable {
            final Runnable b;
            final i.a.n.a.e d;
            final long e;
            long f;

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

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

            a(long j2, Runnable runnable, long j3, i.a.n.a.e eVar, long j4) {
                this.b = runnable;
                this.d = eVar;
                this.e = j4;
                this.f830g = j3;
                this.f831h = j2;
            }

            /* JADX WARN: Removed duplicated region for block: B:10:0x0034  */
            @Override // java.lang.Runnable
            /*
                Code decompiled incorrectly, please refer to instructions dump.
                To view partially-correct add '--show-bad-code' argument
            */
            public void run() {
                /*
                    r10 = this;
                    java.lang.Runnable r0 = r10.b
                    r0.run()
                    i.a.n.a.e r0 = r10.d
                    boolean r0 = r0.isDisposed()
                    if (r0 != 0) goto L53
                    i.a.h$c r0 = i.a.h.c.this
                    java.util.concurrent.TimeUnit r1 = java.util.concurrent.TimeUnit.NANOSECONDS
                    long r0 = r0.a(r1)
                    long r2 = i.a.h.a
                    long r4 = r0 + r2
                    long r6 = r10.f830g
                    int r4 = (r4 > r6 ? 1 : (r4 == r6 ? 0 : -1))
                    r8 = 1
                    if (r4 < 0) goto L34
                    long r4 = r10.e
                    long r6 = r6 + r4
                    long r6 = r6 + r2
                    int r2 = (r0 > r6 ? 1 : (r0 == r6 ? 0 : -1))
                    if (r2 < 0) goto L2a
                    goto L34
                L2a:
                    long r2 = r10.f831h
                    long r6 = r10.f
                    long r6 = r6 + r8
                    r10.f = r6
                    long r6 = r6 * r4
                    long r2 = r2 + r6
                    goto L43
                L34:
                    long r2 = r10.e
                    long r4 = r0 + r2
                    long r6 = r10.f
                    long r6 = r6 + r8
                    r10.f = r6
                    long r2 = r2 * r6
                    long r2 = r4 - r2
                    r10.f831h = r2
                    r2 = r4
                L43:
                    r10.f830g = r0
                    long r2 = r2 - r0
                    i.a.n.a.e r0 = r10.d
                    i.a.h$c r1 = i.a.h.c.this
                    java.util.concurrent.TimeUnit r4 = java.util.concurrent.TimeUnit.NANOSECONDS
                    i.a.k.b r1 = r1.c(r10, r2, r4)
                    r0.a(r1)
                L53:
                    return
                */
                throw new UnsupportedOperationException("Method not decompiled: i.a.h.c.a.run():void");
            }
        }

        public long a(TimeUnit timeUnit) {
            return timeUnit.convert(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
        }

        public i.a.k.b b(Runnable runnable) {
            return c(runnable, 0L, TimeUnit.NANOSECONDS);
        }

        public abstract i.a.k.b c(Runnable runnable, long j2, TimeUnit timeUnit);

        public i.a.k.b d(Runnable runnable, long j2, long j3, TimeUnit timeUnit) {
            i.a.n.a.e eVar = new i.a.n.a.e();
            i.a.n.a.e eVar2 = new i.a.n.a.e(eVar);
            Runnable runnableO = i.a.p.a.o(runnable);
            long nanos = timeUnit.toNanos(j3);
            long jA = a(TimeUnit.NANOSECONDS);
            i.a.k.b bVarC = c(new a(jA + timeUnit.toNanos(j2), runnableO, jA, eVar2, nanos), j2, timeUnit);
            if (bVarC == i.a.n.a.c.INSTANCE) {
                return bVarC;
            }
            eVar.a(bVarC);
            return eVar2;
        }
    }

    public abstract c a();

    public i.a.k.b b(Runnable runnable) {
        return c(runnable, 0L, TimeUnit.NANOSECONDS);
    }

    public i.a.k.b c(Runnable runnable, long j2, TimeUnit timeUnit) {
        c cVarA = a();
        a aVar = new a(i.a.p.a.o(runnable), cVarA);
        cVarA.c(aVar, j2, timeUnit);
        return aVar;
    }

    public i.a.k.b d(Runnable runnable, long j2, long j3, TimeUnit timeUnit) {
        c cVarA = a();
        b bVar = new b(i.a.p.a.o(runnable), cVarA);
        i.a.k.b bVarD = cVarA.d(bVar, j2, j3, timeUnit);
        return bVarD == i.a.n.a.c.INSTANCE ? bVarD : bVar;
    }
}
