1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.internal.storage.pack;
12
13 import java.util.concurrent.locks.ReentrantLock;
14
15 import org.eclipse.jgit.storage.pack.PackConfig;
16
17 class ThreadSafeDeltaCache extends DeltaCache {
18 private final ReentrantLock lock;
19
20 ThreadSafeDeltaCache(PackConfig pc) {
21 super(pc);
22 lock = new ReentrantLock();
23 }
24
25 @Override
26 boolean canCache(int length, ObjectToPack src, ObjectToPack res) {
27 lock.lock();
28 try {
29 return super.canCache(length, src, res);
30 } finally {
31 lock.unlock();
32 }
33 }
34
35 @Override
36 void credit(int reservedSize) {
37 lock.lock();
38 try {
39 super.credit(reservedSize);
40 } finally {
41 lock.unlock();
42 }
43 }
44
45 @Override
46 Ref cache(byte[] data, int actLen, int reservedSize) {
47 data = resize(data, actLen);
48 lock.lock();
49 try {
50 return super.cache(data, actLen, reservedSize);
51 } finally {
52 lock.unlock();
53 }
54 }
55 }