@@ -129,10 +129,22 @@ using RecursiveMutex = AnnotatedMixin<std::recursive_mutex>;
129
129
/* * Wrapped mutex: supports waiting but not recursive locking */
130
130
using Mutex = AnnotatedMixin<std::mutex>;
131
131
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
+
132
143
#define AssertLockHeld (cs ) AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs)
133
144
134
145
inline void AssertLockNotHeldInline (const char * name, const char * file, int line, Mutex* cs) EXCLUSIVE_LOCKS_REQUIRED(!cs) { AssertLockNotHeldInternal (name, file, line, cs); }
135
146
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); }
136
148
#define AssertLockNotHeld (cs ) AssertLockNotHeldInline(#cs, __FILE__, __LINE__, &cs)
137
149
138
150
/* * Wrapper around std::unique_lock style lock for Mutex. */
0 commit comments