The Gcs_tagged_lock class Implements a tagged lock for optimistic read-side sections.
More...
The Gcs_tagged_lock class Implements a tagged lock for optimistic read-side sections.
In a nutshell, the tagged lock is a read-write spin lock which offers the following API:
try_lock() -> bool
unlock()
optimistic_read() -> tag
validate_optimistic_read(tag) -> bool
For the write-side section, one uses it as a typical spin lock, e.g.:
do:
lock_acquired := try_lock()
while (not lock_acquired)
write-side section
unlock()
For the read-side section, one can use it as follows:
done := false
while (not done):
tag := optimistic_read()
unsynchronised read-side section
done := validate_optimistic_read(tag)
if (not done):
rollback unsynchronized read-side section
The idea is to allow an optimistic read-side section that does not perform any memory stores. This is in contrast with a typical read-write lock, where the read side performs some memory stores to account for the reader, e.g. keeping a reader counter. The trade off is that:
a. the execution of the read-side of a tagged lock may be concurrent with the write-side section if meanwhile the tagged lock is acquired b. the read-side of a tagged lock may fail if meanwhile the tagged lock is acquired, in which case one may want to rollback the effects of the failed read-side section
The tagged lock is implemented over a single atomic 64-bit word with the following bit layout:
bit # 64 63 62 3 2 1
+---+---+---+-...-+---+---+---+
| | | | | | | |
+---+---+---+-...-+---+---+---+
\__________ ___________/ \ /
\/ v
tag locked?