package com.google.android.gms.measurement.internal;

import android.os.Process;
import androidx.media3.exoplayer.dash.DashMediaSource;
import java.util.concurrent.BlockingQueue;

/* JADX INFO: loaded from: classes2.dex */
public final class n1 extends Thread {

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

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final /* synthetic */ j1 f21788d;

    public n1(j1 j1Var, String str, BlockingQueue blockingQueue) {
        this.f21788d = j1Var;
        com.google.android.gms.common.internal.w.checkNotNull(str);
        com.google.android.gms.common.internal.w.checkNotNull(blockingQueue);
        this.f21785a = new Object();
        this.f21786b = blockingQueue;
        setName(str);
    }

    public final void a(InterruptedException interruptedException) {
        p0 p0VarZzj = this.f21788d.zzj();
        p0VarZzj.f21837i.b(interruptedException, u1.j(getName(), " was interrupted"));
    }

    public final void b() {
        synchronized (this.f21788d.f21675g) {
            try {
                if (!this.f21787c) {
                    this.f21788d.f21676h.release();
                    this.f21788d.f21675g.notifyAll();
                    if (this == this.f21788d.zzb) {
                        this.f21788d.zzb = null;
                    } else if (this == this.f21788d.zzc) {
                        this.f21788d.zzc = null;
                    } else {
                        this.f21788d.zzj().f21834f.c("Current scheduler thread is neither worker nor network");
                    }
                    this.f21787c = true;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
    }

    @Override // java.lang.Thread, java.lang.Runnable
    public final void run() {
        boolean z10 = false;
        while (!z10) {
            try {
                this.f21788d.f21676h.acquire();
                z10 = true;
            } catch (InterruptedException e10) {
                a(e10);
            }
        }
        try {
            int threadPriority = Process.getThreadPriority(Process.myTid());
            while (true) {
                k1 k1Var = (k1) this.f21786b.poll();
                if (k1Var != null) {
                    Process.setThreadPriority(k1Var.f21699b ? threadPriority : 10);
                    k1Var.run();
                } else {
                    synchronized (this.f21785a) {
                        if (this.f21786b.peek() == null) {
                            this.f21788d.getClass();
                            try {
                                this.f21785a.wait(DashMediaSource.DEFAULT_FALLBACK_TARGET_LIVE_OFFSET_MS);
                            } catch (InterruptedException e11) {
                                a(e11);
                            }
                        }
                    }
                    synchronized (this.f21788d.f21675g) {
                        if (this.f21786b.peek() == null) {
                            b();
                            b();
                            return;
                        }
                    }
                }
            }
        } catch (Throwable th) {
            b();
            throw th;
        }
    }
}
