jimu-decompiled/sources/com/bumptech/glide/load/engine/cache/DiskCacheWriteLocker.java
2025-05-13 19:24:51 +02:00

84 lines
2.3 KiB
Java

package com.bumptech.glide.load.engine.cache;
import com.bumptech.glide.util.Preconditions;
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 DiskCacheWriteLocker {
private final Map<String, WriteLock> a = new HashMap();
private final WriteLockPool b = new WriteLockPool();
private static class WriteLock {
final Lock a = new ReentrantLock();
int b;
WriteLock() {
}
}
DiskCacheWriteLocker() {
}
void a(String str) {
WriteLock writeLock;
synchronized (this) {
writeLock = this.a.get(str);
if (writeLock == null) {
writeLock = this.b.a();
this.a.put(str, writeLock);
}
writeLock.b++;
}
writeLock.a.lock();
}
void b(String str) {
WriteLock writeLock;
synchronized (this) {
WriteLock writeLock2 = this.a.get(str);
Preconditions.a(writeLock2);
writeLock = writeLock2;
if (writeLock.b < 1) {
throw new IllegalStateException("Cannot release a lock that is not held, safeKey: " + str + ", interestedThreads: " + writeLock.b);
}
writeLock.b--;
if (writeLock.b == 0) {
WriteLock remove = this.a.remove(str);
if (!remove.equals(writeLock)) {
throw new IllegalStateException("Removed the wrong lock, expected to remove: " + writeLock + ", but actually removed: " + remove + ", safeKey: " + str);
}
this.b.a(remove);
}
}
writeLock.a.unlock();
}
private static class WriteLockPool {
private final Queue<WriteLock> a = new ArrayDeque();
WriteLockPool() {
}
WriteLock a() {
WriteLock poll;
synchronized (this.a) {
poll = this.a.poll();
}
return poll == null ? new WriteLock() : poll;
}
void a(WriteLock writeLock) {
synchronized (this.a) {
if (this.a.size() < 10) {
this.a.offer(writeLock);
}
}
}
}
}