package d.a.s.g;

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

/* JADX INFO: loaded from: classes.dex */
public final class j extends AtomicReferenceArray<Object> implements Runnable, Callable<Object>, d.a.p.b {

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

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

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

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

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

    public j(Runnable runnable, d.a.s.a.a aVar) {
        super(3);
        this.f5884f = runnable;
        lazySet(0, aVar);
    }

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

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

    @Override // d.a.p.b
    public void dispose() {
        Object obj;
        Object obj2;
        Object obj3;
        Object obj4;
        while (true) {
            Object obj5 = get(1);
            if (obj5 == f5883e || obj5 == (obj3 = f5881c) || obj5 == (obj4 = f5882d)) {
                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 == f5883e || obj == (obj2 = f5880b) || obj == null) {
                return;
            }
        } while (!compareAndSet(0, obj, obj2));
        ((d.a.s.a.a) obj).a(this);
    }

    @Override // d.a.p.b
    public boolean isDisposed() {
        Object obj = get(0);
        return obj == f5880b || obj == f5883e;
    }

    @Override // java.lang.Runnable
    public void run() {
        Object obj;
        Object obj2;
        Object obj3;
        boolean zCompareAndSet;
        Object obj4;
        lazySet(2, Thread.currentThread());
        try {
            this.f5884f.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 != f5880b && compareAndSet(0, obj5, f5883e) && obj5 != null) {
            ((d.a.s.a.a) obj5).a(this);
        }
        do {
            obj4 = get(1);
            if (obj4 == f5881c || obj4 == f5882d) {
                return;
            }
        } while (!compareAndSet(1, obj4, f5883e));
    }
}
