mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 11:57:28 -03:00
sync.h: Add GlobalMutex type
This commit is contained in:
parent
be6aa72f9f
commit
a559509a0b
1 changed files with 12 additions and 0 deletions
12
src/sync.h
12
src/sync.h
|
@ -129,10 +129,22 @@ using RecursiveMutex = AnnotatedMixin<std::recursive_mutex>;
|
|||
/** Wrapped mutex: supports waiting but not recursive locking */
|
||||
using Mutex = AnnotatedMixin<std::mutex>;
|
||||
|
||||
/** Different type to mark Mutex at global scope
|
||||
*
|
||||
* Thread safety analysis can't handle negative assertions about mutexes
|
||||
* with global scope well, so mark them with a separate type, and
|
||||
* eventually move all the mutexes into classes so they are not globally
|
||||
* visible.
|
||||
*
|
||||
* See: https://github.com/bitcoin/bitcoin/pull/20272#issuecomment-720755781
|
||||
*/
|
||||
class GlobalMutex : public Mutex { };
|
||||
|
||||
#define AssertLockHeld(cs) AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs)
|
||||
|
||||
inline void AssertLockNotHeldInline(const char* name, const char* file, int line, Mutex* cs) EXCLUSIVE_LOCKS_REQUIRED(!cs) { AssertLockNotHeldInternal(name, file, line, cs); }
|
||||
inline void AssertLockNotHeldInline(const char* name, const char* file, int line, RecursiveMutex* cs) LOCKS_EXCLUDED(cs) { AssertLockNotHeldInternal(name, file, line, cs); }
|
||||
inline void AssertLockNotHeldInline(const char* name, const char* file, int line, GlobalMutex* cs) LOCKS_EXCLUDED(cs) { AssertLockNotHeldInternal(name, file, line, cs); }
|
||||
#define AssertLockNotHeld(cs) AssertLockNotHeldInline(#cs, __FILE__, __LINE__, &cs)
|
||||
|
||||
/** Wrapper around std::unique_lock style lock for Mutex. */
|
||||
|
|
Loading…
Reference in a new issue