Updated cache logic to be exception-safe.

pull/134/head
Project Nayuki 8 years ago
parent e493029731
commit 71cc6576f6

@ -57,13 +57,18 @@ final class QrTemplate {
} }
} }
try {
QrTemplate tpl = new QrTemplate(version); QrTemplate tpl = new QrTemplate(version);
synchronized(cache) { synchronized(cache) {
cache[version] = new SoftReference<>(tpl); cache[version] = new SoftReference<>(tpl);
}
return tpl;
} finally {
synchronized(cache) {
isPending[version] = false; isPending[version] = false;
cache.notifyAll(); cache.notifyAll();
} }
return tpl; }
} }

@ -59,13 +59,18 @@ final class ReedSolomonGenerator {
} }
} }
try {
ReedSolomonGenerator rs = new ReedSolomonGenerator(degree); ReedSolomonGenerator rs = new ReedSolomonGenerator(degree);
synchronized(cache) { synchronized(cache) {
cache[degree] = new SoftReference<>(rs); cache[degree] = new SoftReference<>(rs);
}
return rs;
} finally {
synchronized(cache) {
isPending[degree] = false; isPending[degree] = false;
cache.notifyAll(); cache.notifyAll();
} }
return rs; }
} }

Loading…
Cancel
Save