package ඓ.ῲ.K.ᕣ.ᨨ.ト;

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;
import ῲ.ᨨ.㳳.C1841;

/* renamed from: ඓ.ῲ.K.ᕣ.ᨨ.ト.ʬ  reason: contains not printable characters */
/* compiled from: DiskCacheWriteLocker */
public final class C0982 {

    /* renamed from: ῲ  reason: contains not printable characters */
    public final C0983 f4367 = new C0983();

    /* renamed from: K  reason: contains not printable characters */
    public final Map<String, C0984> f4368 = new HashMap();

    /* renamed from: ඓ.ῲ.K.ᕣ.ᨨ.ト.ʬ$K  reason: contains not printable characters */
    /* compiled from: DiskCacheWriteLocker */
    public static class C0984 {

        /* renamed from: ῲ  reason: contains not printable characters */
        public int f4370;

        /* renamed from: K  reason: contains not printable characters */
        public final Lock f4371 = new ReentrantLock();
    }

    /* renamed from: ῲ  reason: contains not printable characters */
    public void m2787(String str) {
        C0984 k;
        synchronized (this) {
            C0984 k2 = this.f4368.get(str);
            C1841.m4783(k2, "Argument must not be null");
            k = k2;
            if (k.f4370 >= 1) {
                k.f4370--;
                if (k.f4370 == 0) {
                    C0984 remove = this.f4368.remove(str);
                    if (remove.equals(k)) {
                        this.f4367.m2790(remove);
                    } else {
                        throw new IllegalStateException("Removed the wrong lock, expected to remove: " + k + ", but actually removed: " + remove + ", safeKey: " + str);
                    }
                }
            } else {
                throw new IllegalStateException("Cannot release a lock that is not held, safeKey: " + str + ", interestedThreads: " + k.f4370);
            }
        }
        k.f4371.unlock();
    }

    /* renamed from: K  reason: contains not printable characters */
    public void m2788(String str) {
        C0984 k;
        synchronized (this) {
            k = this.f4368.get(str);
            if (k == null) {
                k = this.f4367.m2789();
                this.f4368.put(str, k);
            }
            k.f4370++;
        }
        k.f4371.lock();
    }

    /* renamed from: ඓ.ῲ.K.ᕣ.ᨨ.ト.ʬ$ῲ  reason: contains not printable characters */
    /* compiled from: DiskCacheWriteLocker */
    public static class C0983 {

        /* renamed from: K  reason: contains not printable characters */
        public final Queue<C0984> f4369 = new ArrayDeque();

        /* renamed from: K  reason: contains not printable characters */
        public C0984 m2789() {
            C0984 poll;
            synchronized (this.f4369) {
                poll = this.f4369.poll();
            }
            return poll == null ? new C0984() : poll;
        }

        /* renamed from: K  reason: contains not printable characters */
        public void m2790(C0984 k) {
            synchronized (this.f4369) {
                if (this.f4369.size() < 10) {
                    this.f4369.offer(k);
                }
            }
        }
    }
}
