Changeset View
Changeset View
Standalone View
Standalone View
src/threadsafety.h
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | |||||
#define EXCLUSIVE_LOCKS_REQUIRED(...) | #define EXCLUSIVE_LOCKS_REQUIRED(...) | ||||
#define SHARED_LOCKS_REQUIRED(...) | #define SHARED_LOCKS_REQUIRED(...) | ||||
#define NO_THREAD_SAFETY_ANALYSIS | #define NO_THREAD_SAFETY_ANALYSIS | ||||
#define ASSERT_EXCLUSIVE_LOCK(...) | #define ASSERT_EXCLUSIVE_LOCK(...) | ||||
#endif // __GNUC__ | #endif // __GNUC__ | ||||
// StdMutex provides an annotated version of std::mutex for us, | // StdMutex provides an annotated version of std::mutex for us, | ||||
// and should only be used when sync.h Mutex/LOCK/etc are not usable. | // and should only be used when sync.h Mutex/LOCK/etc are not usable. | ||||
class LOCKABLE StdMutex : public std::mutex {}; | class LOCKABLE StdMutex : public std::mutex { | ||||
public: | |||||
#ifdef __clang__ | |||||
//! For negative capabilities in the Clang Thread Safety Analysis. | |||||
//! A negative requirement uses the EXCLUSIVE_LOCKS_REQUIRED attribute, in | |||||
//! conjunction with the ! operator, to indicate that a mutex should not be | |||||
//! held. | |||||
const StdMutex &operator!() const { return *this; } | |||||
#endif // __clang__ | |||||
}; | |||||
// StdLockGuard provides an annotated version of std::lock_guard for us, | // StdLockGuard provides an annotated version of std::lock_guard for us, | ||||
// and should only be used when sync.h Mutex/LOCK/etc are not usable. | // and should only be used when sync.h Mutex/LOCK/etc are not usable. | ||||
class SCOPED_LOCKABLE StdLockGuard : public std::lock_guard<StdMutex> { | class SCOPED_LOCKABLE StdLockGuard : public std::lock_guard<StdMutex> { | ||||
public: | public: | ||||
explicit StdLockGuard(StdMutex &cs) EXCLUSIVE_LOCK_FUNCTION(cs) | explicit StdLockGuard(StdMutex &cs) EXCLUSIVE_LOCK_FUNCTION(cs) | ||||
: std::lock_guard<StdMutex>(cs) {} | : std::lock_guard<StdMutex>(cs) {} | ||||
~StdLockGuard() UNLOCK_FUNCTION() {} | ~StdLockGuard() UNLOCK_FUNCTION() {} | ||||
}; | }; | ||||
#endif // BITCOIN_THREADSAFETY_H | #endif // BITCOIN_THREADSAFETY_H |