|
1 | 1 | package com.bumptech.glide.load.engine.cache;
|
2 | 2 |
|
3 |
| -import com.bumptech.glide.load.Key; |
4 | 3 | import com.bumptech.glide.util.Preconditions;
|
5 | 4 | import com.bumptech.glide.util.Synthetic;
|
6 | 5 | import java.util.ArrayDeque;
|
|
19 | 18 | * 0, the lock can safely be removed from the map. </p>
|
20 | 19 | */
|
21 | 20 | final class DiskCacheWriteLocker {
|
22 |
| - private final Map<Key, WriteLock> locks = new HashMap<>(); |
| 21 | + private final Map<String, WriteLock> locks = new HashMap<>(); |
23 | 22 | private final WriteLockPool writeLockPool = new WriteLockPool();
|
24 | 23 |
|
25 |
| - void acquire(Key key) { |
| 24 | + void acquire(String safeKey) { |
26 | 25 | WriteLock writeLock;
|
27 | 26 | synchronized (this) {
|
28 |
| - writeLock = locks.get(key); |
| 27 | + writeLock = locks.get(safeKey); |
29 | 28 | if (writeLock == null) {
|
30 | 29 | writeLock = writeLockPool.obtain();
|
31 |
| - locks.put(key, writeLock); |
| 30 | + locks.put(safeKey, writeLock); |
32 | 31 | }
|
33 | 32 | writeLock.interestedThreads++;
|
34 | 33 | }
|
35 | 34 |
|
36 | 35 | writeLock.lock.lock();
|
37 | 36 | }
|
38 | 37 |
|
39 |
| - void release(Key key) { |
| 38 | + void release(String safeKey) { |
40 | 39 | WriteLock writeLock;
|
41 | 40 | synchronized (this) {
|
42 |
| - writeLock = Preconditions.checkNotNull(locks.get(key)); |
| 41 | + writeLock = Preconditions.checkNotNull(locks.get(safeKey)); |
43 | 42 | if (writeLock.interestedThreads < 1) {
|
44 | 43 | throw new IllegalStateException("Cannot release a lock that is not held"
|
45 |
| - + ", key: " + key |
| 44 | + + ", safeKey: " + safeKey |
46 | 45 | + ", interestedThreads: " + writeLock.interestedThreads);
|
47 | 46 | }
|
48 | 47 |
|
49 | 48 | writeLock.interestedThreads--;
|
50 | 49 | if (writeLock.interestedThreads == 0) {
|
51 |
| - WriteLock removed = locks.remove(key); |
| 50 | + WriteLock removed = locks.remove(safeKey); |
52 | 51 | if (!removed.equals(writeLock)) {
|
53 | 52 | throw new IllegalStateException("Removed the wrong lock"
|
54 | 53 | + ", expected to remove: " + writeLock
|
55 | 54 | + ", but actually removed: " + removed
|
56 |
| - + ", key: " + key); |
| 55 | + + ", safeKey: " + safeKey); |
57 | 56 | }
|
58 | 57 | writeLockPool.offer(removed);
|
59 | 58 | }
|
|
0 commit comments