package o;

import android.os.Process;
import com.google.android.gms.common.internal.Preconditions;
import java.util.concurrent.BlockingQueue;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* loaded from: classes.dex */
public final class Dr0 extends Thread {
    public final Object l;
    public final BlockingQueue m;
    public boolean n = false;

    /* renamed from: o, reason: collision with root package name */
    public final /* synthetic */ Fr0 f89o;

    public Dr0(Fr0 fr0, String str, BlockingQueue blockingQueue) {
        this.f89o = fr0;
        Preconditions.checkNotNull(str);
        Preconditions.checkNotNull(blockingQueue);
        this.l = new Object();
        this.m = blockingQueue;
        setName(str);
    }

    public final void a() {
        Fr0 fr0 = this.f89o;
        synchronized (fr0.i) {
            try {
                if (!this.n) {
                    fr0.j.release();
                    fr0.i.notifyAll();
                    if (this == fr0.c) {
                        fr0.c = null;
                    } else if (this == fr0.d) {
                        fr0.d = null;
                    } else {
                        Nq0 nq0 = ((Kr0) fr0.a).f;
                        Kr0.l(nq0);
                        nq0.f.b("Current scheduler thread is neither worker nor network");
                    }
                    this.n = true;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override // java.lang.Thread, java.lang.Runnable
    public final void run() throws InterruptedException {
        boolean z = false;
        while (!z) {
            try {
                this.f89o.j.acquire();
                z = true;
            } catch (InterruptedException e) {
                Nq0 nq0 = ((Kr0) this.f89o.a).f;
                Kr0.l(nq0);
                nq0.i.c(e, String.valueOf(getName()).concat(" was interrupted"));
            }
        }
        try {
            int threadPriority = Process.getThreadPriority(Process.myTid());
            while (true) {
                BlockingQueue blockingQueue = this.m;
                Cr0 cr0 = (Cr0) blockingQueue.poll();
                if (cr0 != null) {
                    Process.setThreadPriority(true != cr0.m ? 10 : threadPriority);
                    cr0.run();
                } else {
                    Object obj = this.l;
                    synchronized (obj) {
                        if (blockingQueue.peek() == null) {
                            this.f89o.getClass();
                            try {
                                obj.wait(30000L);
                            } catch (InterruptedException e2) {
                                Nq0 nq02 = ((Kr0) this.f89o.a).f;
                                Kr0.l(nq02);
                                nq02.i.c(e2, String.valueOf(getName()).concat(" was interrupted"));
                            }
                        }
                    }
                    synchronized (this.f89o.i) {
                        if (this.m.peek() == null) {
                            a();
                            a();
                            return;
                        }
                    }
                }
            }
        } catch (Throwable th) {
            a();
            throw th;
        }
    }
}
