package J3;

import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.LockSupport;
import m1.AbstractC2464a;

/* JADX INFO: loaded from: classes3.dex */
public final class E extends AtomicReference implements Runnable {

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

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final Callable f3504a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final /* synthetic */ F f3505b;

    public E(F f6, Callable callable) {
        this.f3505b = f6;
        callable.getClass();
        this.f3504a = callable;
    }

    public final void a(Thread thread) {
        Runnable runnable = (Runnable) get();
        t tVar = null;
        boolean z6 = false;
        int i6 = 0;
        while (true) {
            boolean z7 = runnable instanceof t;
            u uVar = f3503d;
            if (!z7 && runnable != uVar) {
                break;
            }
            if (z7) {
                tVar = (t) runnable;
            }
            i6++;
            if (i6 <= 1000) {
                Thread.yield();
            } else if (runnable == uVar || compareAndSet(runnable, uVar)) {
                z6 = Thread.interrupted() || z6;
                LockSupport.park(tVar);
            }
            runnable = (Runnable) get();
        }
        if (z6) {
            thread.interrupt();
        }
    }

    @Override // java.lang.Runnable
    public final void run() {
        Object objCall;
        Thread threadCurrentThread = Thread.currentThread();
        if (compareAndSet(null, threadCurrentThread)) {
            F f6 = this.f3505b;
            boolean zIsDone = f6.isDone();
            u uVar = f3502c;
            if (zIsDone) {
                objCall = null;
            } else {
                try {
                    objCall = this.f3504a.call();
                } catch (Throwable th) {
                    try {
                        if (th instanceof InterruptedException) {
                            Thread.currentThread().interrupt();
                        }
                        if (!compareAndSet(threadCurrentThread, uVar)) {
                            a(threadCurrentThread);
                        }
                        if (zIsDone) {
                            return;
                        }
                        f6.k(th);
                        return;
                    } catch (Throwable th2) {
                        if (!compareAndSet(threadCurrentThread, uVar)) {
                            a(threadCurrentThread);
                        }
                        if (!zIsDone) {
                            f6.getClass();
                            if (p.f3534f.o(f6, null, p.f3535j)) {
                                p.d(f6, false);
                            }
                        }
                        throw th2;
                    }
                }
            }
            if (!compareAndSet(threadCurrentThread, uVar)) {
                a(threadCurrentThread);
            }
            if (zIsDone) {
                return;
            }
            f6.getClass();
            if (objCall == null) {
                objCall = p.f3535j;
            }
            if (p.f3534f.o(f6, null, objCall)) {
                p.d(f6, false);
            }
        }
    }

    @Override // java.util.concurrent.atomic.AtomicReference
    public final String toString() {
        String str;
        Runnable runnable = (Runnable) get();
        if (runnable == f3502c) {
            str = "running=[DONE]";
        } else if (runnable instanceof t) {
            str = "running=[INTERRUPTED]";
        } else if (runnable instanceof Thread) {
            str = "running=[RUNNING ON " + ((Thread) runnable).getName() + "]";
        } else {
            str = "running=[NOT STARTED YET]";
        }
        StringBuilder sbB = AbstractC2464a.b(str, ", ");
        sbB.append(this.f3504a.toString());
        return sbB.toString();
    }
}
