package m4;

import java.util.ArrayDeque;
import java.util.concurrent.Executor;
import java.util.logging.Level;
import java.util.logging.Logger;

/* JADX INFO: loaded from: classes3.dex */
public final class W1 implements Executor {

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public boolean f20903a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public ArrayDeque f20904b;

    public final void a() {
        while (true) {
            Runnable runnable = (Runnable) this.f20904b.poll();
            if (runnable == null) {
                return;
            }
            try {
                runnable.run();
            } catch (Throwable th) {
                f20902c.log(Level.SEVERE, "Exception while executing runnable " + runnable, th);
            }
        }
    }

    @Override // java.util.concurrent.Executor
    public final void execute(Runnable runnable) {
        A4.g.o(runnable, "'task' must not be null.");
        if (this.f20903a) {
            if (this.f20904b == null) {
                this.f20904b = new ArrayDeque(4);
            }
            this.f20904b.add(runnable);
            return;
        }
        this.f20903a = true;
        try {
            runnable.run();
        } catch (Throwable th) {
            try {
                f20902c.log(Level.SEVERE, "Exception while executing runnable " + runnable, th);
                if (this.f20904b != null) {
                    a();
                }
                this.f20903a = false;
            } finally {
                if (this.f20904b != null) {
                    a();
                }
                this.f20903a = false;
            }
        }
    }
}
