package e.a.u.g;

import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicReferenceArray;

/* JADX INFO: compiled from: ScheduledRunnable.java */
/* JADX INFO: loaded from: classes.dex */
public final class i extends AtomicReferenceArray<Object> implements Runnable, Callable<Object>, e.a.r.b {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    static final Object f3831f = new Object();

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    static final Object f3832g = new Object();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    final Runnable f3833b;

    public i(Runnable runnable, e.a.u.a.a aVar) {
        super(3);
        this.f3833b = runnable;
        lazySet(0, aVar);
    }

    public void a(Future<?> future) {
        Object obj;
        do {
            obj = get(1);
            if (obj == f3832g) {
                return;
            }
            if (obj == f3831f) {
                future.cancel(get(2) != Thread.currentThread());
                return;
            }
        } while (!compareAndSet(1, obj, future));
    }

    @Override // java.util.concurrent.Callable
    public Object call() {
        run();
        return null;
    }

    @Override // e.a.r.b
    public void dispose() {
        Object obj;
        Object obj2;
        Object obj3;
        while (true) {
            Object obj4 = get(1);
            if (obj4 == f3832g || obj4 == (obj3 = f3831f)) {
                break;
            } else if (compareAndSet(1, obj4, obj3)) {
                if (obj4 != null) {
                    ((Future) obj4).cancel(get(2) != Thread.currentThread());
                }
            }
        }
        do {
            obj = get(0);
            if (obj == f3832g || obj == (obj2 = f3831f) || obj == null) {
                return;
            }
        } while (!compareAndSet(0, obj, obj2));
        ((e.a.u.a.a) obj).a(this);
    }

    @Override // e.a.r.b
    public boolean isDisposed() {
        Object obj = get(1);
        return obj == f3831f || obj == f3832g;
    }

    @Override // java.lang.Runnable
    public void run() {
        Object obj;
        Object obj2;
        boolean zCompareAndSet;
        Object obj3;
        lazySet(2, Thread.currentThread());
        try {
            this.f3833b.run();
        } finally {
            try {
            } catch (Throwable th) {
                do {
                    if (obj == obj2) {
                        break;
                    }
                } while (!zCompareAndSet);
            }
        }
        lazySet(2, null);
        Object obj4 = get(0);
        if (obj4 != f3831f && obj4 != null && compareAndSet(0, obj4, f3832g)) {
            ((e.a.u.a.a) obj4).a(this);
        }
        do {
            obj3 = get(1);
            if (obj3 == f3831f) {
                return;
            }
        } while (!compareAndSet(1, obj3, f3832g));
    }
}
