SimpleCache: Tweak comments related to blocking

"Write case, lock not available" was a bit confusing. When the
content is not cached and the lock is held, it's neither a read
or a write case. It's a "can't do anything" case. When blocking,
it may subsequently turn into either a read or a write.

PiperOrigin-RevId: 250530722
This commit is contained in:
olly 2019-05-29 19:23:42 +01:00 committed by Toni
parent 71418f9411
commit ed5ce2396d

View File

@ -390,10 +390,11 @@ public final class SimpleCache implements Cache {
if (span != null) {
return span;
} else {
// Write case, lock not available. We'll be woken up when a locked span is released (if the
// released lock is for the requested key then we'll be able to make progress) or when a
// span is added to the cache (if the span is for the requested key and covers the requested
// position, then we'll become a read and be able to make progress).
// Lock not available. We'll be woken up when a span is added, or when a locked span is
// released. We'll be able to make progress when either:
// 1. A span is added for the requested key that covers the requested position, in which
// case a read can be started.
// 2. The lock for the requested key is released, in which case a write can be started.
wait();
}
}
@ -415,12 +416,12 @@ public final class SimpleCache implements Cache {
CachedContent cachedContent = contentIndex.getOrAdd(key);
if (!cachedContent.isLocked()) {
// Write case, lock available.
// Write case.
cachedContent.setLocked(true);
return span;
}
// Write case, lock not available.
// Lock not available.
return null;
}