Skip to content

Commit 436ce02

Browse files
committed
sync.h: strengthen AssertLockNotHeld assertion
1 parent 7d73f58 commit 436ce02

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/sync.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLi
8383
inline void DeleteLock(void* cs) {}
8484
inline bool LockStackEmpty() { return true; }
8585
#endif
86-
#define AssertLockHeld(cs) AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs)
87-
#define AssertLockNotHeld(cs) AssertLockNotHeldInternal(#cs, __FILE__, __LINE__, &cs)
8886

8987
/**
9088
* Template mixin that adds -Wthread-safety locking annotations and lock order
@@ -129,7 +127,13 @@ class LOCKABLE AnnotatedMixin : public PARENT
129127
using RecursiveMutex = AnnotatedMixin<std::recursive_mutex>;
130128

131129
/** Wrapped mutex: supports waiting but not recursive locking */
132-
typedef AnnotatedMixin<std::mutex> Mutex;
130+
using Mutex = AnnotatedMixin<std::mutex>;
131+
132+
#define AssertLockHeld(cs) AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs)
133+
134+
inline void AssertLockNotHeldInline(const char* name, const char* file, int line, Mutex* cs) EXCLUSIVE_LOCKS_REQUIRED(!cs) { AssertLockNotHeldInternal(name, file, line, cs); }
135+
inline void AssertLockNotHeldInline(const char* name, const char* file, int line, RecursiveMutex* cs) LOCKS_EXCLUDED(cs) { AssertLockNotHeldInternal(name, file, line, cs); }
136+
#define AssertLockNotHeld(cs) AssertLockNotHeldInline(#cs, __FILE__, __LINE__, &cs)
133137

134138
/** Wrapper around std::unique_lock style lock for Mutex. */
135139
template <typename Mutex, typename Base = typename Mutex::UniqueLock>

0 commit comments

Comments
 (0)