package u1; import java.util.ArrayDeque; import java.util.HashMap; import java.util.Map; import java.util.Queue; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; /* loaded from: classes.dex */ final class c { /* renamed from: a, reason: collision with root package name */ private final Map f14636a = new HashMap(); /* renamed from: b, reason: collision with root package name */ private final b f14637b = new b(); private static class a { /* renamed from: a, reason: collision with root package name */ final Lock f14638a = new ReentrantLock(); /* renamed from: b, reason: collision with root package name */ int f14639b; a() { } } private static class b { /* renamed from: a, reason: collision with root package name */ private final Queue f14640a = new ArrayDeque(); b() { } a a() { a aVar; synchronized (this.f14640a) { aVar = (a) this.f14640a.poll(); } return aVar == null ? new a() : aVar; } void b(a aVar) { synchronized (this.f14640a) { if (this.f14640a.size() < 10) { this.f14640a.offer(aVar); } } } } c() { } void a(String str) { a aVar; synchronized (this) { aVar = (a) this.f14636a.get(str); if (aVar == null) { aVar = this.f14637b.a(); this.f14636a.put(str, aVar); } aVar.f14639b++; } aVar.f14638a.lock(); } void b(String str) { a aVar; synchronized (this) { aVar = (a) m2.j.d(this.f14636a.get(str)); int i10 = aVar.f14639b; if (i10 < 1) { throw new IllegalStateException("Cannot release a lock that is not held, safeKey: " + str + ", interestedThreads: " + aVar.f14639b); } int i11 = i10 - 1; aVar.f14639b = i11; if (i11 == 0) { a aVar2 = (a) this.f14636a.remove(str); if (!aVar2.equals(aVar)) { throw new IllegalStateException("Removed the wrong lock, expected to remove: " + aVar + ", but actually removed: " + aVar2 + ", safeKey: " + str); } this.f14637b.b(aVar2); } } aVar.f14638a.unlock(); } }