package j6; 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: classes2.dex */ final class j { /* renamed from: a, reason: collision with root package name */ private final Map f11100a = new HashMap(); /* renamed from: b, reason: collision with root package name */ private final b f11101b = new b(); private static class a { /* renamed from: a, reason: collision with root package name */ final Lock f11102a = new ReentrantLock(); /* renamed from: b, reason: collision with root package name */ int f11103b; a() { } } private static class b { /* renamed from: a, reason: collision with root package name */ private final Queue f11104a = new ArrayDeque(); b() { } a a() { a aVar; synchronized (this.f11104a) { aVar = (a) this.f11104a.poll(); } return aVar == null ? new a() : aVar; } void b(a aVar) { synchronized (this.f11104a) { if (this.f11104a.size() < 10) { this.f11104a.offer(aVar); } } } } j() { } void a(String str) { a aVar; synchronized (this) { aVar = (a) this.f11100a.get(str); if (aVar == null) { aVar = this.f11101b.a(); this.f11100a.put(str, aVar); } aVar.f11103b++; } aVar.f11102a.lock(); } void b(String str) { a aVar; synchronized (this) { aVar = (a) b7.j.d((a) this.f11100a.get(str)); int i10 = aVar.f11103b; if (i10 < 1) { throw new IllegalStateException("Cannot release a lock that is not held, safeKey: " + str + ", interestedThreads: " + aVar.f11103b); } int i11 = i10 - 1; aVar.f11103b = i11; if (i11 == 0) { a aVar2 = (a) this.f11100a.remove(str); if (!aVar2.equals(aVar)) { throw new IllegalStateException("Removed the wrong lock, expected to remove: " + aVar + ", but actually removed: " + aVar2 + ", safeKey: " + str); } this.f11101b.b(aVar2); } } aVar.f11102a.unlock(); } }