diff --git a/src/logging.h b/src/logging.h index e21495015b6..803bdac1c42 100644 --- a/src/logging.h +++ b/src/logging.h @@ -8,9 +8,9 @@ #include #include // IWYU pragma: export -#include #include #include // IWYU pragma: export +#include #include #include diff --git a/src/threadsafety.h b/src/threadsafety.h index b79d4c76458..35f3b813273 100644 --- a/src/threadsafety.h +++ b/src/threadsafety.h @@ -6,8 +6,6 @@ #ifndef BITCOIN_THREADSAFETY_H #define BITCOIN_THREADSAFETY_H -#include - #ifdef __clang__ // TL;DR Add GUARDED_BY(mutex) to member variables. The others are // rarely necessary. Ex: int nFoo GUARDED_BY(cs_foo); @@ -54,26 +52,4 @@ #define ASSERT_EXCLUSIVE_LOCK(...) #endif // __GNUC__ -// StdMutex provides an annotated version of std::mutex for us, -// and should only be used when sync.h Mutex/LOCK/etc are not usable. -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, -// and should only be used when sync.h Mutex/LOCK/etc are not usable. -class SCOPED_LOCKABLE StdLockGuard : public std::lock_guard -{ -public: - explicit StdLockGuard(StdMutex& cs) EXCLUSIVE_LOCK_FUNCTION(cs) : std::lock_guard(cs) {} - ~StdLockGuard() UNLOCK_FUNCTION() = default; -}; - #endif // BITCOIN_THREADSAFETY_H diff --git a/src/util/stdmutex.h b/src/util/stdmutex.h new file mode 100644 index 00000000000..4c3c0cec5ed --- /dev/null +++ b/src/util/stdmutex.h @@ -0,0 +1,35 @@ +// Copyright (c) 2009-2010 Satoshi Nakamoto +// Copyright (c) 2009-present The Bitcoin Core developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#ifndef BITCOIN_UTIL_STDMUTEX_H +#define BITCOIN_UTIL_STDMUTEX_H + +#include // IWYU pragma: export + +#include + +// StdMutex provides an annotated version of std::mutex for us, +// and should only be used when sync.h Mutex/LOCK/etc are not usable. +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, +// and should only be used when sync.h Mutex/LOCK/etc are not usable. +class SCOPED_LOCKABLE StdLockGuard : public std::lock_guard +{ +public: + explicit StdLockGuard(StdMutex& cs) EXCLUSIVE_LOCK_FUNCTION(cs) : std::lock_guard(cs) {} + ~StdLockGuard() UNLOCK_FUNCTION() = default; +}; + +#endif // BITCOIN_UTIL_STDMUTEX_H