package d3;

import android.os.Process;
import java.util.AbstractQueue;
import java.util.concurrent.BlockingQueue;

/* JADX INFO: renamed from: d3.p0, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0812p0 extends Thread {

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

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final AbstractQueue f12096r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public boolean f12097s = false;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final /* synthetic */ C0815q0 f12098t;

    /* JADX WARN: Multi-variable type inference failed */
    public C0812p0(C0815q0 c0815q0, String str, BlockingQueue blockingQueue) {
        this.f12098t = c0815q0;
        P2.w.f(blockingQueue);
        this.f12095q = new Object();
        this.f12096r = (AbstractQueue) blockingQueue;
        setName(str);
    }

    public final void a() {
        Object obj = this.f12095q;
        synchronized (obj) {
            obj.notifyAll();
        }
    }

    public final void b() {
        C0815q0 c0815q0 = this.f12098t;
        synchronized (c0815q0.f12111y) {
            try {
                if (!this.f12097s) {
                    c0815q0.f12112z.release();
                    c0815q0.f12111y.notifyAll();
                    if (this == c0815q0.f12105s) {
                        c0815q0.f12105s = null;
                    } else if (this == c0815q0.f12106t) {
                        c0815q0.f12106t = null;
                    } else {
                        Z z8 = ((C0817r0) c0815q0.f5146q).f12150y;
                        C0817r0.k(z8);
                        z8.f11875v.b("Current scheduler thread is neither worker nor network");
                    }
                    this.f12097s = true;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override // java.lang.Thread, java.lang.Runnable
    public final void run() {
        boolean z8 = false;
        while (!z8) {
            try {
                this.f12098t.f12112z.acquire();
                z8 = true;
            } catch (InterruptedException e8) {
                Z z9 = ((C0817r0) this.f12098t.f5146q).f12150y;
                C0817r0.k(z9);
                z9.f11878y.c(e8, String.valueOf(getName()).concat(" was interrupted"));
            }
        }
        try {
            int threadPriority = Process.getThreadPriority(Process.myTid());
            while (true) {
                AbstractQueue abstractQueue = this.f12096r;
                C0809o0 c0809o0 = (C0809o0) abstractQueue.poll();
                if (c0809o0 != null) {
                    Process.setThreadPriority(true != c0809o0.f12081r ? 10 : threadPriority);
                    c0809o0.run();
                } else {
                    Object obj = this.f12095q;
                    synchronized (obj) {
                        if (abstractQueue.peek() == null) {
                            this.f12098t.getClass();
                            try {
                                obj.wait(30000L);
                            } catch (InterruptedException e9) {
                                Z z10 = ((C0817r0) this.f12098t.f5146q).f12150y;
                                C0817r0.k(z10);
                                z10.f11878y.c(e9, String.valueOf(getName()).concat(" was interrupted"));
                            }
                        }
                    }
                    synchronized (this.f12098t.f12111y) {
                        if (this.f12096r.peek() == null) {
                            b();
                            b();
                            return;
                        }
                    }
                }
            }
        } catch (Throwable th) {
            b();
            throw th;
        }
    }
}
