mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 14:08:40 +01:00
sync.h: Add GlobalMutex type
This commit is contained in:
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. */
|
||||
|
||||
Reference in New Issue
Block a user