From f393a533bebc088985f94c725b9af881500ba998 Mon Sep 17 00:00:00 2001 From: Jesse Cohen Date: Fri, 8 Jun 2018 14:06:58 -0400 Subject: Annotate AssertLockHeld() with ASSERT_CAPABILITY() for thread safety analysis --- src/sync.h | 4 ++-- src/threadsafety.h | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/sync.h b/src/sync.h index 3c451af376..882ad5dc4c 100644 --- a/src/sync.h +++ b/src/sync.h @@ -74,13 +74,13 @@ public: void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false); void LeaveCritical(); std::string LocksHeld(); -void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs); +void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) ASSERT_EXCLUSIVE_LOCK(cs); void AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs); void DeleteLock(void* cs); #else void static inline EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false) {} void static inline LeaveCritical() {} -void static inline AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) {} +void static inline AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) ASSERT_EXCLUSIVE_LOCK(cs) {} void static inline AssertLockNotHeldInternal(const char* pszName, const char* pszFile, int nLine, void* cs) {} void static inline DeleteLock(void* cs) {} #endif diff --git a/src/threadsafety.h b/src/threadsafety.h index 61e63dbc7a..d847269dff 100644 --- a/src/threadsafety.h +++ b/src/threadsafety.h @@ -31,6 +31,7 @@ #define EXCLUSIVE_LOCKS_REQUIRED(...) __attribute__((exclusive_locks_required(__VA_ARGS__))) #define SHARED_LOCKS_REQUIRED(...) __attribute__((shared_locks_required(__VA_ARGS__))) #define NO_THREAD_SAFETY_ANALYSIS __attribute__((no_thread_safety_analysis)) +#define ASSERT_EXCLUSIVE_LOCK(...) __attribute((assert_exclusive_lock(__VA_ARGS__))) #else #define LOCKABLE #define SCOPED_LOCKABLE @@ -50,6 +51,7 @@ #define EXCLUSIVE_LOCKS_REQUIRED(...) #define SHARED_LOCKS_REQUIRED(...) #define NO_THREAD_SAFETY_ANALYSIS +#define ASSERT_EXCLUSIVE_LOCK(...) #endif // __GNUC__ #endif // BITCOIN_THREADSAFETY_H -- cgit v1.2.3