package o; import com.bumptech.glide.load.engine.GlideException; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.atomic.AtomicInteger; import o.C1050UnO; import o.RDy; import o.RunnableC3281aua; import o.ykj; import o.zuk; /* loaded from: classes.dex */ public final class DoN implements RunnableC3281aua.RVV, C1050UnO.Sts { private static final LWm g = new LWm(); private boolean C; RunnableC3281aua a; final ExecutorServiceC0913Rjq b; pNW c; zuk d; final IeS e; private final ExecutorServiceC0913Rjq f; GlideException h; boolean i; boolean j; private final InterfaceC17110txV k; private boolean l; private boolean m; private final LWm n; /* renamed from: o, reason: collision with root package name */ private boolean f8135o; private final AtomicInteger p; private volatile boolean q; private InterfaceC2545agd r; private final RDy.Sts> s; private Ezi t; private final zuk.HBt u; private boolean v; private final ExecutorServiceC0913Rjq w; private final ExecutorServiceC0913Rjq x; private final ykj y; /* JADX INFO: Access modifiers changed from: package-private */ public DoN(ExecutorServiceC0913Rjq executorServiceC0913Rjq, ExecutorServiceC0913Rjq executorServiceC0913Rjq2, ExecutorServiceC0913Rjq executorServiceC0913Rjq3, ExecutorServiceC0913Rjq executorServiceC0913Rjq4, InterfaceC17110txV interfaceC17110txV, zuk.HBt hBt, RDy.Sts> sts) { this(executorServiceC0913Rjq, executorServiceC0913Rjq2, executorServiceC0913Rjq3, executorServiceC0913Rjq4, interfaceC17110txV, hBt, sts, g); } private DoN(ExecutorServiceC0913Rjq executorServiceC0913Rjq, ExecutorServiceC0913Rjq executorServiceC0913Rjq2, ExecutorServiceC0913Rjq executorServiceC0913Rjq3, ExecutorServiceC0913Rjq executorServiceC0913Rjq4, InterfaceC17110txV interfaceC17110txV, zuk.HBt hBt, RDy.Sts> sts, LWm lWm) { this.e = new IeS(); this.y = new ykj.LWm(); this.p = new AtomicInteger(); this.b = executorServiceC0913Rjq; this.w = executorServiceC0913Rjq2; this.x = executorServiceC0913Rjq3; this.f = executorServiceC0913Rjq4; this.k = interfaceC17110txV; this.u = hBt; this.s = sts; this.n = lWm; } /* JADX INFO: Access modifiers changed from: package-private */ public final DoN b(InterfaceC2545agd interfaceC2545agd, boolean z, boolean z2, boolean z3, boolean z4) { synchronized (this) { this.r = interfaceC2545agd; this.f8135o = z; this.C = z2; this.v = z3; this.i = z4; } return this; } /* JADX INFO: Access modifiers changed from: package-private */ public final void a(oWF owf, Executor executor) { synchronized (this) { this.y.b(); this.e.d.add(new RVV(owf, executor)); if (this.m) { a(1); executor.execute(new HBt(this, owf)); } else if (this.l) { a(1); executor.execute(new Sts(this, owf)); } else if (!(!this.q)) { throw new IllegalArgumentException("Cannot add callbacks to a cancelled EngineJob"); } } } public final void a(oWF owf) { synchronized (this) { this.y.b(); this.e.d.remove(new RVV(owf, C3107arK.e())); if (this.e.d.isEmpty()) { if (!this.l && !this.m && !this.q) { this.q = true; RunnableC3281aua runnableC3281aua = this.a; runnableC3281aua.j = true; XGP xgp = runnableC3281aua.d; if (xgp != null) { xgp.e(); } this.k.c(this, this.r); } if ((this.m || this.l) && this.p.get() == 0) { e(); } } } } final void a() { zuk zukVar; synchronized (this) { this.y.b(); if (this.l || this.m || this.q) { int decrementAndGet = this.p.decrementAndGet(); if (!(decrementAndGet >= 0)) { throw new IllegalArgumentException("Can't decrement below 0"); } if (decrementAndGet == 0) { zukVar = this.d; e(); } else { zukVar = null; } } else { throw new IllegalArgumentException("Not yet complete!"); } } if (zukVar != null) { zukVar.g(); } } private void e() { synchronized (this) { if (this.r == null) { throw new IllegalArgumentException(); } this.e.d.clear(); this.r = null; this.d = null; this.t = null; this.l = false; this.q = false; this.m = false; this.j = false; RunnableC3281aua runnableC3281aua = this.a; if (runnableC3281aua.t.b()) { runnableC3281aua.e(); } this.a = null; this.h = null; this.c = null; this.s.d(this); } } /* JADX WARN: Multi-variable type inference failed */ @Override // o.RunnableC3281aua.RVV public final void b(Ezi ezi, pNW pnw, boolean z) { synchronized (this) { this.t = ezi; this.c = pnw; this.j = z; } synchronized (this) { this.y.b(); if (this.q) { this.t.b(); e(); return; } if (!this.e.d.isEmpty()) { if (this.m) { throw new IllegalStateException("Already have resource"); } this.d = new zuk<>(this.t, this.f8135o, true, this.r, this.u); this.m = true; IeS ieS = new IeS(new ArrayList(this.e.d)); a(ieS.d.size() + 1); this.k.d(this, this.r, this.d); Iterator it = ieS.iterator(); while (it.hasNext()) { RVV next = it.next(); next.d.execute(new HBt(this, next.c)); } a(); return; } throw new IllegalStateException("Received a resource without any callbacks to notify"); } } @Override // o.RunnableC3281aua.RVV public final void d(GlideException glideException) { synchronized (this) { this.h = glideException; } synchronized (this) { this.y.b(); if (this.q) { e(); return; } if (!this.e.d.isEmpty()) { if (this.l) { throw new IllegalStateException("Already failed once"); } this.l = true; InterfaceC2545agd interfaceC2545agd = this.r; IeS ieS = new IeS(new ArrayList(this.e.d)); a(ieS.d.size() + 1); this.k.d(this, interfaceC2545agd, null); Iterator it = ieS.iterator(); while (it.hasNext()) { RVV next = it.next(); next.d.execute(new Sts(this, next.c)); } a(); return; } throw new IllegalStateException("Received an exception without any callbacks to notify"); } } @Override // o.RunnableC3281aua.RVV public final void c(RunnableC3281aua runnableC3281aua) { d().execute(runnableC3281aua); } /* loaded from: classes.dex */ class Sts implements Runnable { private DoN c; private final oWF e; Sts(DoN doN, oWF owf) { this.c = doN; this.e = owf; } @Override // java.lang.Runnable public final void run() { synchronized (this.e.e()) { synchronized (this.c) { if (this.c.e.d.contains(new RVV(this.e, C3107arK.e()))) { DoN doN = this.c; try { this.e.c(doN.h); } catch (Throwable th) { throw new oco(th); } } this.c.a(); } } } } /* loaded from: classes.dex */ class HBt implements Runnable { private final oWF a; private DoN e; HBt(DoN doN, oWF owf) { this.e = doN; this.a = owf; } @Override // java.lang.Runnable public final void run() { synchronized (this.a.e()) { synchronized (this.e) { if (this.e.e.d.contains(new RVV(this.a, C3107arK.e()))) { this.e.d.c(); DoN doN = this.e; oWF owf = this.a; try { zuk zukVar = doN.d; pNW pnw = doN.c; boolean z = doN.j; owf.b(zukVar, pnw); this.e.a(this.a); } catch (Throwable th) { throw new oco(th); } } this.e.a(); } } } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public static final class IeS implements Iterable { final List d; IeS() { this(new ArrayList(2)); } IeS(List list) { this.d = list; } @Override // java.lang.Iterable public final Iterator iterator() { return this.d.iterator(); } } /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes.dex */ public static final class RVV { final oWF c; final Executor d; RVV(oWF owf, Executor executor) { this.c = owf; this.d = executor; } public final boolean equals(Object obj) { if (obj instanceof RVV) { return this.c.equals(((RVV) obj).c); } return false; } public final int hashCode() { return this.c.hashCode(); } } /* loaded from: classes.dex */ static class LWm { LWm() { } } private void a(int i) { zuk zukVar; synchronized (this) { if (this.l || this.m || this.q) { if (this.p.getAndAdd(i) == 0 && (zukVar = this.d) != null) { zukVar.c(); } } else { throw new IllegalArgumentException("Not yet complete!"); } } } @Override // o.C1050UnO.Sts public final ykj c() { return this.y; } /* JADX INFO: Access modifiers changed from: package-private */ public final ExecutorServiceC0913Rjq d() { return this.C ? this.x : this.v ? this.f : this.w; } }