This is one of several PRs to cleanup/modernize our threading primitives.
While replacing the old critical section locks in the mining code with a REVERSE_LOCK
, I noticed that our thread-safety annotations weren’t hooked up to it. This PR gets REVERSE_LOCK
working properly.
Firstly it modernizes the attributes as-recommended by the clang docs (ctrl+f for USE_LOCK_STYLE_THREAD_SAFETY_ATTRIBUTES
). There’s a subtle difference between the old unlock_function
and new release_capability
, where our reverse_lock
only works with the latter. I believe this is an upstream bug. I’ve reported and attempted a fix here, but either way it makes sense to me to modernize.
The second commit just fixes an unrelated logging bug that I noticed while hacking around in here.
The third adds a missing annotation pointed out by a fixed REVERSE_LOCK
. Because clang’s thread-safety annotations aren’t passed through a reference to UniqueLock
as one may assume (see here for more details), cs_main
has to be listed explicitly as a requirement.
The last commit actually fixes the reverse_lock
by making it a SCOPED_LOCK
and using the pattern found in a clang test. Though the docs don’t describe how to accomplish it, the functionality was added in this commit. Due to aliasing issues (see link above), in order to work correctly, the original mutex has to be passed along with the lock, so all existing REVERSE_LOCK
s have been updated. To ensure that the mutexes actually match, a runtime assertion is added.