Skip to content

Commit

Permalink
SimpleCache: Tweak comments related to blocking
Browse files Browse the repository at this point in the history
"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
  • Loading branch information
ojw28 authored and tonihei committed May 30, 2019
1 parent 71418f9 commit ed5ce23
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -390,10 +390,11 @@ public synchronized SimpleCacheSpan startReadWrite(String key, long position)
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();
}
}
Expand All @@ -415,12 +416,12 @@ public synchronized SimpleCacheSpan startReadWriteNonBlocking(String key, long p

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;
}

Expand Down

0 comments on commit ed5ce23

Please sign in to comment.