package com.google.android.gms.measurement.internal; import com.google.android.gms.common.internal.Preconditions; import java.lang.Thread; import java.util.concurrent.BlockingQueue; import java.util.concurrent.Callable; import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.PriorityBlockingQueue; import java.util.concurrent.Semaphore; import java.util.concurrent.atomic.AtomicLong; /* loaded from: classes.dex */ public final class zzbr extends zzcs { private static final AtomicLong l = new AtomicLong(Long.MIN_VALUE); private zzbv c; private zzbv d; private final PriorityBlockingQueue> e; private final BlockingQueue> f; private final Thread.UncaughtExceptionHandler g; private final Thread.UncaughtExceptionHandler h; private final Object i; private final Semaphore j; private volatile boolean k; zzbr(zzbw zzbwVar) { super(zzbwVar); this.i = new Object(); this.j = new Semaphore(2); this.e = new PriorityBlockingQueue<>(); this.f = new LinkedBlockingQueue(); this.g = new zzbt(this, "Thread death: Uncaught exception on worker thread"); this.h = new zzbt(this, "Thread death: Uncaught exception on network thread"); } public final Future a(Callable callable) throws IllegalStateException { o(); Preconditions.a(callable); zzbu zzbuVar = new zzbu<>(this, (Callable) callable, false, "Task exception on worker thread"); if (Thread.currentThread() == this.c) { if (!this.e.isEmpty()) { e().w().a("Callable skipped the worker queue."); } zzbuVar.run(); } else { a(zzbuVar); } return zzbuVar; } public final Future b(Callable callable) throws IllegalStateException { o(); Preconditions.a(callable); zzbu zzbuVar = new zzbu<>(this, (Callable) callable, true, "Task exception on worker thread"); if (Thread.currentThread() == this.c) { zzbuVar.run(); } else { a(zzbuVar); } return zzbuVar; } @Override // com.google.android.gms.measurement.internal.zzcr public final void f() { if (Thread.currentThread() != this.c) { throw new IllegalStateException("Call expected from worker thread"); } } @Override // com.google.android.gms.measurement.internal.zzcr public final void h() { if (Thread.currentThread() != this.d) { throw new IllegalStateException("Call expected from network thread"); } } @Override // com.google.android.gms.measurement.internal.zzcs protected final boolean q() { return false; } public final boolean t() { return Thread.currentThread() == this.c; } public final void b(Runnable runnable) throws IllegalStateException { o(); Preconditions.a(runnable); zzbu zzbuVar = new zzbu<>(this, runnable, false, "Task exception on network thread"); synchronized (this.i) { this.f.add(zzbuVar); if (this.d == null) { this.d = new zzbv(this, "Measurement Network", this.f); this.d.setUncaughtExceptionHandler(this.h); this.d.start(); } else { this.d.a(); } } } public final void a(Runnable runnable) throws IllegalStateException { o(); Preconditions.a(runnable); a(new zzbu<>(this, runnable, false, "Task exception on worker thread")); } private final void a(zzbu zzbuVar) { synchronized (this.i) { this.e.add(zzbuVar); if (this.c == null) { this.c = new zzbv(this, "Measurement Worker", this.e); this.c.setUncaughtExceptionHandler(this.g); this.c.start(); } else { this.c.a(); } } } static /* synthetic */ zzbv b(zzbr zzbrVar, zzbv zzbvVar) { zzbrVar.d = null; return null; } static /* synthetic */ zzbv a(zzbr zzbrVar, zzbv zzbvVar) { zzbrVar.c = null; return null; } }