This PR is a simple 3-line scripted diff followed by a documentation cleanup. The scripted diff does three things:
- Deletes all existing
AssertLockHeld
calls. Since #19668,AssertLockHeld
has had anEXCLUSIVE_LOCKS_REQUIRED
annotation which has guaranteed (though ongoing travis and cirrus CI builds since #19668 was merged) that theseAssertLockHeld
calls are redundant withEXCLUSIVE_LOCKS_REQUIRED
orEXCLUSIVE_LOCK_FUNCTION
annotations already present in surrounding code, and specifically that:
- There is no way the assert calls can trigger any behavior at runtime.
- The assert calls provide no new thread safety information to the compiler.
-
Reverts
AssertLockHeld
implementation which got changed in #19668 to it’s original pre-#19668 state. In #19668,AssertLockHeld
was changed to have anEXCLUSIVE_LOCKS_REQUIRED
annotation instead of having anASSERT_EXCLUSIVE_LOCK
annotation. As described above, having anEXCLUSIVE_LOCKS_REQUIRED
annotation on an assert statement is only useful as proof that the assert statement doesn’t do anything or convey any new information. By contrast, having anASSERT_EXCLUSIVE_LOCK
annotation on an assert statement can be an actually useful way of conveying to the compiler than a specific mutex is locked at a specific place in the code, when the compiler thread safety analysis can’t determine that on its own (because of lost type information). -
Removes
LockAssertion
class, replacing all current uses with calls toAssertLockHeld
. Ever since theLockAssertion
class was first introduced in #14437 (asLockAnnotation
), it has always been an inferior alternative toAssertLockHeld
and not had a reason to exist. (#14437 was originally written before #13423 which added ASSERT_EXCLUSIVE_LOCK annotation. It was justified when the code was first written, but no longer necessary by the time it was merged).
Motivation for this PR is to get rid of confusion between different types of lock assertions and only keep one assertion: AssertLockHeld
which goes back to the implementation it’s had since #13423 was merged until #19668 was merged. After this PR, AssertLockHeld
only needs to be used sparingly to augment compile-time thread safety annotations, which are a superior alternative to runtime checks for guaranteeing thread safety.
PR is compared with alternatives in https://github.com/bitcoin-core/bitcoin-devwiki/wiki/AssertLockHeld-PRs