package e;

import java.util.ArrayDeque;
import java.util.concurrent.Executor;

/* JADX INFO: loaded from: classes.dex */
public final class u implements Executor {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f25331a;

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public Runnable f25333c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Object f25334d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final ArrayDeque f25335e;

    public u(Executor executor, int i10) {
        this.f25331a = i10;
        if (i10 != 1) {
            this.f25334d = new Object();
            this.f25335e = new ArrayDeque();
            this.f25332b = executor;
        } else {
            nb.g.i(executor, "executor");
            this.f25332b = executor;
            this.f25335e = new ArrayDeque();
            this.f25334d = new Object();
        }
    }

    public final void a() {
        switch (this.f25331a) {
            case 0:
                synchronized (this.f25334d) {
                    try {
                        Runnable runnable = (Runnable) this.f25335e.poll();
                        this.f25333c = runnable;
                        if (runnable != null) {
                            this.f25332b.execute(runnable);
                        }
                    } catch (Throwable th) {
                        throw th;
                    }
                    break;
                }
                return;
            default:
                synchronized (this.f25334d) {
                    Object objPoll = this.f25335e.poll();
                    Runnable runnable2 = (Runnable) objPoll;
                    this.f25333c = runnable2;
                    if (objPoll != null) {
                        this.f25332b.execute(runnable2);
                    }
                    break;
                }
                return;
        }
    }

    @Override // java.util.concurrent.Executor
    public final void execute(Runnable runnable) {
        switch (this.f25331a) {
            case 0:
                synchronized (this.f25334d) {
                    try {
                        this.f25335e.add(new t(this, runnable, 0));
                        if (this.f25333c == null) {
                            a();
                        }
                    } catch (Throwable th) {
                        throw th;
                    }
                    break;
                }
                return;
            default:
                nb.g.i(runnable, "command");
                synchronized (this.f25334d) {
                    this.f25335e.offer(new t(this, runnable));
                    if (this.f25333c == null) {
                        a();
                    }
                    break;
                }
                return;
        }
    }
}
