package f.a.n.g;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;
import java.util.concurrent.atomic.AtomicReference;

/* JADX INFO: compiled from: InstantPeriodicTask.java */
/* JADX INFO: loaded from: classes.dex */
final class c implements Callable<Void>, f.a.k.b {

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    static final FutureTask<Void> f883i = new FutureTask<>(f.a.n.b.a.a, null);
    final Runnable b;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    final ExecutorService f886g;

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    final AtomicReference<Future<?>> f885f = new AtomicReference<>();

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    final AtomicReference<Future<?>> f884e = new AtomicReference<>();

    c(Runnable runnable, ExecutorService executorService) {
        this.b = runnable;
        this.f886g = executorService;
    }

    @Override // java.util.concurrent.Callable
    /* JADX INFO: renamed from: a, reason: merged with bridge method [inline-methods] */
    public Void call() throws Exception {
        try {
            this.f887h = Thread.currentThread();
            try {
                this.b.run();
                c(this.f886g.submit(this));
            } catch (Throwable th) {
                f.a.p.a.m(th);
            }
            return null;
        } finally {
            this.f887h = null;
        }
    }

    void b(Future<?> future) {
        Future<?> future2;
        do {
            future2 = this.f885f.get();
            if (future2 == f883i) {
                future.cancel(this.f887h != Thread.currentThread());
            }
        } while (!this.f885f.compareAndSet(future2, future));
    }

    void c(Future<?> future) {
        Future<?> future2;
        do {
            future2 = this.f884e.get();
            if (future2 == f883i) {
                future.cancel(this.f887h != Thread.currentThread());
            }
        } while (!this.f884e.compareAndSet(future2, future));
    }

    @Override // f.a.k.b
    public void dispose() {
        Future<?> andSet = this.f885f.getAndSet(f883i);
        if (andSet != null && andSet != f883i) {
            andSet.cancel(this.f887h != Thread.currentThread());
        }
        Future<?> andSet2 = this.f884e.getAndSet(f883i);
        if (andSet2 == null || andSet2 == f883i) {
            return;
        }
        andSet2.cancel(this.f887h != Thread.currentThread());
    }
}
