package com.google.firebase.concurrent;

import com.google.android.gms.common.internal.w;
import java.util.ArrayDeque;
import java.util.concurrent.Executor;
import java.util.concurrent.RejectedExecutionException;
import java.util.logging.Logger;

/* JADX INFO: loaded from: classes2.dex */
public final class b implements Executor {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final Logger f24057f = Logger.getLogger(b.class.getName());

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

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public SequentialExecutor$WorkerRunningState f24060c = SequentialExecutor$WorkerRunningState.f24046a;

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final a f24062e = new a(this, 0);

    public b(Executor executor) {
        this.f24058a = (Executor) w.checkNotNull(executor);
    }

    /* JADX WARN: Removed duplicated region for block: B:43:0x0061  */
    @Override // java.util.concurrent.Executor
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void execute(Runnable runnable) {
        SequentialExecutor$WorkerRunningState sequentialExecutor$WorkerRunningState;
        boolean z10;
        w.checkNotNull(runnable);
        synchronized (this.f24059b) {
            SequentialExecutor$WorkerRunningState sequentialExecutor$WorkerRunningState2 = this.f24060c;
            if (sequentialExecutor$WorkerRunningState2 != SequentialExecutor$WorkerRunningState.f24049d && sequentialExecutor$WorkerRunningState2 != (sequentialExecutor$WorkerRunningState = SequentialExecutor$WorkerRunningState.f24048c)) {
                long j10 = this.f24061d;
                a aVar = new a(this, runnable);
                this.f24059b.add(aVar);
                SequentialExecutor$WorkerRunningState sequentialExecutor$WorkerRunningState3 = SequentialExecutor$WorkerRunningState.f24047b;
                this.f24060c = sequentialExecutor$WorkerRunningState3;
                try {
                    this.f24058a.execute(this.f24062e);
                    if (this.f24060c != sequentialExecutor$WorkerRunningState3) {
                        return;
                    }
                    synchronized (this.f24059b) {
                        try {
                            if (this.f24061d == j10 && this.f24060c == sequentialExecutor$WorkerRunningState3) {
                                this.f24060c = sequentialExecutor$WorkerRunningState;
                            }
                        } finally {
                        }
                    }
                    return;
                } catch (Error | RuntimeException e10) {
                    synchronized (this.f24059b) {
                        try {
                            SequentialExecutor$WorkerRunningState sequentialExecutor$WorkerRunningState4 = this.f24060c;
                            if (sequentialExecutor$WorkerRunningState4 == SequentialExecutor$WorkerRunningState.f24046a || sequentialExecutor$WorkerRunningState4 == SequentialExecutor$WorkerRunningState.f24047b) {
                                z10 = this.f24059b.removeLastOccurrence(aVar);
                            }
                            if (!(e10 instanceof RejectedExecutionException) || z10) {
                                throw e10;
                            }
                        } finally {
                        }
                    }
                    return;
                }
            }
            this.f24059b.add(runnable);
        }
    }

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