package O2;

import java.util.ArrayDeque;
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
import java.util.logging.Logger;
import s1.z;
import s2.RunnableC1013a;

/* JADX INFO: loaded from: classes.dex */
public final class k implements Executor {
    public static final Logger p = Logger.getLogger(k.class.getName());

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final Executor f2306k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final ArrayDeque f2307l = new ArrayDeque();

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public int f2308m = 1;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public long f2309n = 0;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final RunnableC1013a f2310o = new RunnableC1013a(this);

    public k(Executor executor) {
        z.g(executor);
        this.f2306k = executor;
    }

    @Override // java.util.concurrent.Executor
    public final void execute(Runnable runnable) {
        z.g(runnable);
        synchronized (this.f2307l) {
            int i = this.f2308m;
            if (i != 4 && i != 3) {
                long j5 = this.f2309n;
                j jVar = new j(runnable, 0);
                this.f2307l.add(jVar);
                this.f2308m = 2;
                try {
                    this.f2306k.execute(this.f2310o);
                    if (this.f2308m != 2) {
                        return;
                    }
                    synchronized (this.f2307l) {
                        try {
                            if (this.f2309n == j5 && this.f2308m == 2) {
                                this.f2308m = 3;
                            }
                        } finally {
                        }
                    }
                    return;
                } catch (Error | RuntimeException e2) {
                    synchronized (this.f2307l) {
                        try {
                            int i5 = this.f2308m;
                            boolean z5 = true;
                            if ((i5 != 1 && i5 != 2) || !this.f2307l.removeLastOccurrence(jVar)) {
                                z5 = false;
                            }
                            if (!(e2 instanceof RejectedExecutionException) || z5) {
                                throw e2;
                            }
                        } finally {
                        }
                    }
                    return;
                }
            }
            this.f2307l.add(runnable);
        }
    }

    public final String toString() {
        return "SequentialExecutor@" + System.identityHashCode(this) + "{" + this.f2306k + "}";
    }
}
