Skip to content

Commit f393a53

Browse files
committed
Annotate AssertLockHeld() with ASSERT_CAPABILITY() for thread safety analysis
1 parent 29b4ee6 commit f393a53

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/sync.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,13 +74,13 @@ class LOCKABLE AnnotatedMixin : public PARENT
7474
void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false);
7575
void LeaveCritical();
7676
std::string LocksHeld();
77-
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs);
77+
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) ASSERT_EXCLUSIVE_LOCK(cs);
7878
void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs);
7979
void DeleteLock(void* cs);
8080
#else
8181
void static inline EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false) {}
8282
void static inline LeaveCritical() {}
83-
void static inline AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) {}
83+
void static inline AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) ASSERT_EXCLUSIVE_LOCK(cs) {}
8484
void static inline AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) {}
8585
void static inline DeleteLock(void* cs) {}
8686
#endif

src/threadsafety.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
#define EXCLUSIVE_LOCKS_REQUIRED(...) __attribute__((exclusive_locks_required(__VA_ARGS__)))
3232
#define SHARED_LOCKS_REQUIRED(...) __attribute__((shared_locks_required(__VA_ARGS__)))
3333
#define NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis))
34+
#define ASSERT_EXCLUSIVE_LOCK(...) __attribute((assert_exclusive_lock(__VA_ARGS__)))
3435
#else
3536
#define LOCKABLE
3637
#define SCOPED_LOCKABLE
@@ -50,6 +51,7 @@
5051
#define EXCLUSIVE_LOCKS_REQUIRED(...)
5152
#define SHARED_LOCKS_REQUIRED(...)
5253
#define NO_THREAD_SAFETY_ANALYSIS
54+
#define ASSERT_EXCLUSIVE_LOCK(...)
5355
#endif // __GNUC__
5456

5557
#endif // BITCOIN_THREADSAFETY_H

0 commit comments

Comments
 (0)