Skip to content

Commit a559509

Browse files
committed
sync.h: Add GlobalMutex type
1 parent be6aa72 commit a559509

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/sync.h

+12
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,22 @@ using RecursiveMutex = AnnotatedMixin<std::recursive_mutex>;
129129
/** Wrapped mutex: supports waiting but not recursive locking */
130130
using Mutex = AnnotatedMixin<std::mutex>;
131131

132+
/** Different type to mark Mutex at global scope
133+
*
134+
* Thread safety analysis can't handle negative assertions about mutexes
135+
* with global scope well, so mark them with a separate type, and
136+
* eventually move all the mutexes into classes so they are not globally
137+
* visible.
138+
*
139+
* See: https://github.com/bitcoin/bitcoin/pull/20272#issuecomment-720755781
140+
*/
141+
class GlobalMutex : public Mutex { };
142+
132143
#define AssertLockHeld(cs) AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs)
133144

134145
inline void AssertLockNotHeldInline(const char* name, const char* file, int line, Mutex* cs) EXCLUSIVE_LOCKS_REQUIRED(!cs) { AssertLockNotHeldInternal(name, file, line, cs); }
135146
inline void AssertLockNotHeldInline(const char* name, const char* file, int line, RecursiveMutex* cs) LOCKS_EXCLUDED(cs) { AssertLockNotHeldInternal(name, file, line, cs); }
147+
inline void AssertLockNotHeldInline(const char* name, const char* file, int line, GlobalMutex* cs) LOCKS_EXCLUDED(cs) { AssertLockNotHeldInternal(name, file, line, cs); }
136148
#define AssertLockNotHeld(cs) AssertLockNotHeldInline(#cs, __FILE__, __LINE__, &cs)
137149

138150
/** Wrapper around std::unique_lock style lock for Mutex. */

0 commit comments

Comments
 (0)