Correct a technical flaw with the spinlock locking:

The existing spinlock code, used to protect SHAMapInnerNode
child lists, has a mistake that can allow the same child to
be repeatedly locked under some circumstances.

The bug was in the `SpinBitLock::lock` loop condition check
and would result in the loop terminating early.

This commit fixes this and further simplifies the lock loop
making the correctness of the code easier to verify without
sacrificing performance.

It also promotes the spinlock class from an implementation
detail to a more general purpose, easier to use lock class
with clearer semantics. Two different lock types now allow
developers to easily grab either a single spinlock from an
a group of spinlocks (packed in an unsigned integer) or to
grab all of the spinlocks at once.

While this commit makes spinlocks more widely available to
developers, they are rarely the best tool for the job. Use
them judiciously and only after careful consideration.
This commit is contained in:
Nik Bougalis
2022-06-08 12:18:04 -07:00
parent 59326bbbc5
commit 7e46f5342b
3 changed files with 229 additions and 88 deletions

View File

@@ -156,6 +156,7 @@ install (
src/ripple/basics/MathUtilities.h
src/ripple/basics/safe_cast.h
src/ripple/basics/Slice.h
src/ripple/basics/spinlock.h
src/ripple/basics/StringUtilities.h
src/ripple/basics/ThreadSafetyAnalysis.h
src/ripple/basics/ToString.h