package IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.XnFJ5_9;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.LockSupport;
/* compiled from: FileLock.java */
/* loaded from: classes.dex */
public class PGPF6hQ_2 {
    public static final long KQgRr5e_0 = TimeUnit.MILLISECONDS.toNanos(100);

    /* renamed from: KQgRr5e_0  reason: collision with other field name */
    public final Map<String, AtomicInteger> f187KQgRr5e_0;
    public final Map<String, Thread> QxJ9d_1;

    public PGPF6hQ_2(Map<String, AtomicInteger> map, Map<String, Thread> map2) {
        this.f187KQgRr5e_0 = map;
        this.QxJ9d_1 = map2;
    }

    public void KQgRr5e_0(String str) {
        AtomicInteger atomicInteger;
        Thread thread;
        synchronized (this.f187KQgRr5e_0) {
            atomicInteger = this.f187KQgRr5e_0.get(str);
        }
        if (atomicInteger == null || atomicInteger.decrementAndGet() != 0) {
            return;
        }
        IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.PGPF6hQ_2.KQgRr5e_0("FileLock", "decreaseLock decrease lock-count to 0 " + str);
        synchronized (this.QxJ9d_1) {
            thread = this.QxJ9d_1.get(str);
            if (thread != null) {
                this.QxJ9d_1.remove(str);
            }
        }
        if (thread != null) {
            IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.PGPF6hQ_2.KQgRr5e_0("FileLock", "decreaseLock " + str + " unpark locked thread " + atomicInteger);
            KQgRr5e_0(thread);
        }
        synchronized (this.f187KQgRr5e_0) {
            this.f187KQgRr5e_0.remove(str);
        }
    }

    public void PGPF6hQ_2(String str) {
        AtomicInteger atomicInteger;
        synchronized (this.f187KQgRr5e_0) {
            atomicInteger = this.f187KQgRr5e_0.get(str);
        }
        if (atomicInteger == null || atomicInteger.get() <= 0) {
            return;
        }
        synchronized (this.QxJ9d_1) {
            this.QxJ9d_1.put(str, Thread.currentThread());
        }
        IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.PGPF6hQ_2.KQgRr5e_0("FileLock", "waitForRelease start " + str);
        while (!KQgRr5e_0(atomicInteger)) {
            KQgRr5e_0();
        }
        IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.PGPF6hQ_2.KQgRr5e_0("FileLock", "waitForRelease finish " + str);
    }

    public void QxJ9d_1(String str) {
        AtomicInteger atomicInteger;
        synchronized (this.f187KQgRr5e_0) {
            atomicInteger = this.f187KQgRr5e_0.get(str);
        }
        if (atomicInteger == null) {
            atomicInteger = new AtomicInteger(0);
            synchronized (this.f187KQgRr5e_0) {
                this.f187KQgRr5e_0.put(str, atomicInteger);
            }
        }
        IMuAHx_6.KQgRr5e_0.KQgRr5e_0.XnFJ5_9.PGPF6hQ_2.KQgRr5e_0("FileLock", "increaseLock increase lock-count to " + atomicInteger.incrementAndGet() + str);
    }

    public PGPF6hQ_2() {
        this(new HashMap(), new HashMap());
    }

    public boolean KQgRr5e_0(AtomicInteger atomicInteger) {
        return atomicInteger.get() <= 0;
    }

    public void KQgRr5e_0() {
        LockSupport.park(Long.valueOf(KQgRr5e_0));
    }

    public void KQgRr5e_0(Thread thread) {
        LockSupport.unpark(thread);
    }
}
