aboutsummaryrefslogtreecommitdiff
path: root/src/threadsafety.h
diff options
context:
space:
mode:
authorHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2020-05-28 09:32:21 +0300
committerHennadii Stepanov <32963518+hebasto@users.noreply.github.com>2020-05-28 09:54:09 +0300
commit79be4874209f71ba6428a80c40c9f028ac936c41 (patch)
tree67705aa6de8960a452eaa2a4ecf3b44d5b7b2a4c /src/threadsafety.h
parent55b4c65bd1d829e799db7fe75fab88691830de43 (diff)
downloadbitcoin-79be4874209f71ba6428a80c40c9f028ac936c41.tar.xz
Add thread safety annotated wrapper for std::mutex
Co-authored-by: Anthony Towns <aj@erisian.com.au>
Diffstat (limited to 'src/threadsafety.h')
-rw-r--r--src/threadsafety.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/threadsafety.h b/src/threadsafety.h
index 81f86eac3a..404ecafebb 100644
--- a/src/threadsafety.h
+++ b/src/threadsafety.h
@@ -56,12 +56,18 @@
#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
+{
+};
+
// LockGuard provides an annotated version of lock_guard for us
// should only be used when sync.h Mutex/LOCK/etc aren't usable
-class SCOPED_LOCKABLE LockGuard : public std::lock_guard<std::mutex>
+class SCOPED_LOCKABLE LockGuard : public std::lock_guard<StdMutex>
{
public:
- explicit LockGuard(std::mutex& cs) EXCLUSIVE_LOCK_FUNCTION(cs) : std::lock_guard<std::mutex>(cs) { }
+ explicit LockGuard(StdMutex& cs) EXCLUSIVE_LOCK_FUNCTION(cs) : std::lock_guard<StdMutex>(cs) {}
~LockGuard() UNLOCK_FUNCTION() {};
};