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

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

Loading…
Cancel
Save