package i6;

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

/* loaded from: classes.dex */
public class h implements Executor {

    /* renamed from: q, reason: collision with root package name */
    private final Executor f22456q;

    /* renamed from: s, reason: collision with root package name */
    private volatile Runnable f22458s;

    /* renamed from: p, reason: collision with root package name */
    private final ArrayDeque f22455p = new ArrayDeque();

    /* renamed from: r, reason: collision with root package name */
    private final Object f22457r = new Object();

    /* loaded from: classes.dex */
    static class a implements Runnable {

        /* renamed from: p, reason: collision with root package name */
        final h f22459p;

        /* renamed from: q, reason: collision with root package name */
        final Runnable f22460q;

        a(h hVar, Runnable runnable) {
            this.f22459p = hVar;
            this.f22460q = runnable;
        }

        @Override // java.lang.Runnable
        public void run() {
            try {
                this.f22460q.run();
            } finally {
                this.f22459p.b();
            }
        }
    }

    public h(Executor executor) {
        this.f22456q = executor;
    }

    public boolean a() {
        boolean z10;
        synchronized (this.f22457r) {
            z10 = !this.f22455p.isEmpty();
        }
        return z10;
    }

    void b() {
        synchronized (this.f22457r) {
            Runnable runnable = (Runnable) this.f22455p.poll();
            this.f22458s = runnable;
            if (runnable != null) {
                this.f22456q.execute(this.f22458s);
            }
        }
    }

    @Override // java.util.concurrent.Executor
    public void execute(Runnable runnable) {
        synchronized (this.f22457r) {
            this.f22455p.add(new a(this, runnable));
            if (this.f22458s == null) {
                b();
            }
        }
    }
}
