1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2025-05-31 22:44:34 +00:00

Mass_parse: Add thread-locking to LRU cache [#518]

This commit is contained in:
gnosygnu 2019-07-23 22:47:22 -04:00
parent 5c8b70fd76
commit 436f219477

View File

@ -66,24 +66,31 @@ public class Lru_cache {
} }
} }
public void Clear_all() { public void Clear_all() {
synchronized (map) {
map.Clear(); map.Clear();
head = null; head = null;
tail = null; tail = null;
cur = 0; cur = 0;
}
} }
public void Clear_min(long size) { public void Clear_min(long size) {
synchronized (map) {
long threshold = min >= 0 ? min : max; long threshold = min >= 0 ? min : max;
while (cur + size > threshold) { while (cur + size > threshold) {
Del_node_from_this(head); Del_node_from_this(head);
evicts++; evicts++;
} }
}
} }
private void Del_node_from_this(Lru_node nde) { private void Del_node_from_this(Lru_node nde) {
synchronized (map) {
map.Del(nde.Key()); map.Del(nde.Key());
cur -= nde.Size(); cur -= nde.Size();
Del_node_from_linked_list(nde); Del_node_from_linked_list(nde);
}
} }
private void Del_node_from_linked_list(Lru_node nde) { private void Del_node_from_linked_list(Lru_node nde) {
synchronized (map) {
if (nde.Prv() == null) if (nde.Prv() == null)
head = nde.Nxt(); head = nde.Nxt();
else else
@ -93,8 +100,10 @@ public class Lru_cache {
tail = nde.Prv(); tail = nde.Prv();
else else
nde.Nxt().Prv_(nde.Prv()); nde.Nxt().Prv_(nde.Prv());
}
} }
private void Add_to_tail(Lru_node nde) { private void Add_to_tail(Lru_node nde) {
synchronized (map) {
if (tail != null) if (tail != null)
tail.Nxt_(nde); tail.Nxt_(nde);
@ -104,6 +113,7 @@ public class Lru_cache {
if (head == null) if (head == null)
head = tail; head = tail;
}
} }
public void To_str(Bry_bfr bfr, boolean grps_only_or_both) { public void To_str(Bry_bfr bfr, boolean grps_only_or_both) {
bfr.Add_str_a7("g"); bfr.Add_str_a7("g");