package f.a.w.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 l extends AtomicReferenceArray<Object> implements Runnable, Callable<Object>, f.a.t.b {

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

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

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

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final Runnable f4011h;

    public l(Runnable runnable, f.a.w.a.a aVar) {
        super(3);
        this.f4011h = runnable;
        lazySet(0, aVar);
    }

    public void a(Future<?> future) {
        Object obj;
        do {
            obj = get(1);
            if (obj == f4010g) {
                return;
            }
            if (obj == f4008e) {
                future.cancel(false);
                return;
            } else if (obj == f4009f) {
                future.cancel(true);
                return;
            }
        } while (!compareAndSet(1, obj, future));
    }

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

    @Override // f.a.t.b
    public void dispose() {
        Object obj;
        Object obj2;
        Object obj3;
        Object obj4;
        while (true) {
            Object obj5 = get(1);
            if (obj5 == f4010g || obj5 == (obj3 = f4008e) || obj5 == (obj4 = f4009f)) {
                break;
            }
            boolean z = get(2) != Thread.currentThread();
            if (z) {
                obj3 = obj4;
            }
            if (compareAndSet(1, obj5, obj3)) {
                if (obj5 != null) {
                    ((Future) obj5).cancel(z);
                }
            }
        }
        do {
            obj = get(0);
            if (obj == f4010g || obj == (obj2 = f4007b) || obj == null) {
                return;
            }
        } while (!compareAndSet(0, obj, obj2));
        ((f.a.w.a.a) obj).c(this);
    }

    @Override // java.lang.Runnable
    public void run() {
        Object obj;
        Object obj2;
        Object obj3;
        boolean zCompareAndSet;
        Object obj4;
        lazySet(2, Thread.currentThread());
        try {
            this.f4011h.run();
        } finally {
            try {
            } catch (Throwable th) {
                do {
                    if (obj == obj2) {
                        break;
                    } else if (obj == obj3) {
                        break;
                    }
                } while (!zCompareAndSet);
            }
        }
        lazySet(2, null);
        Object obj5 = get(0);
        if (obj5 != f4007b && compareAndSet(0, obj5, f4010g) && obj5 != null) {
            ((f.a.w.a.a) obj5).c(this);
        }
        do {
            obj4 = get(1);
            if (obj4 == f4008e || obj4 == f4009f) {
                return;
            }
        } while (!compareAndSet(1, obj4, f4010g));
    }
}
