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 {
} }
} }
QrTemplate tpl = new QrTemplate(version); try {
synchronized(cache) { QrTemplate tpl = new QrTemplate(version);
cache[version] = new SoftReference<>(tpl); synchronized(cache) {
isPending[version] = false; cache[version] = new SoftReference<>(tpl);
cache.notifyAll(); }
return tpl;
} finally {
synchronized(cache) {
isPending[version] = false;
cache.notifyAll();
}
} }
return tpl;
} }

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

Loading…
Cancel
Save