@@ -129,10 +129,22 @@ using RecursiveMutex = AnnotatedMixin<std::recursive_mutex>;
129129/* * Wrapped mutex: supports waiting but not recursive locking */
130130using 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
134145inline void AssertLockNotHeldInline (const char * name, const char * file, int line, Mutex* cs) EXCLUSIVE_LOCKS_REQUIRED(!cs) { AssertLockNotHeldInternal (name, file, line, cs); }
135146inline 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