diff options
author | Anthony Towns <aj@erisian.com.au> | 2022-04-20 17:09:20 +1000 |
---|---|---|
committer | Anthony Towns <aj@erisian.com.au> | 2022-05-21 01:23:23 +1000 |
commit | a559509a0b8cade27199740212d7b589f71a0e3b (patch) | |
tree | e7bfb7b674dda21c530eece0dcbb3127fcc9c77c /src/sync.h | |
parent | be6aa72f9f8d50b6b5b19b319a74abe7ab4099ff (diff) |
sync.h: Add GlobalMutex type
Diffstat (limited to 'src/sync.h')
-rw-r--r-- | src/sync.h | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/src/sync.h b/src/sync.h index a175926113..b094b5d2e2 100644 --- a/src/sync.h +++ b/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. */ |