aboutsummaryrefslogtreecommitdiff
path: root/src/sync.h
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2012-12-12 09:27:35 -0800
committerGavin Andresen <gavinandresen@gmail.com>2012-12-12 09:27:35 -0800
commit8a7277a578463a647664b068b6b7b69cf09cda57 (patch)
treec9476bd8d25c92ed83d97bf91c0dfe4fe1cfa738 /src/sync.h
parent50894e4fd47efe207bff3db9978b7a22979822c7 (diff)
parent25511af4a57816c4f9bb960527f090a9719c9010 (diff)
downloadbitcoin-8a7277a578463a647664b068b6b7b69cf09cda57.tar.xz
Merge pull request #2003 from alexanderkjeldaas/documented-locking-part-2
Documented locking part 1+2
Diffstat (limited to 'src/sync.h')
-rw-r--r--src/sync.h25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/sync.h b/src/sync.h
index 9dfc6697c6..930c9b2b80 100644
--- a/src/sync.h
+++ b/src/sync.h
@@ -9,15 +9,36 @@
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/locks.hpp>
#include <boost/thread/condition_variable.hpp>
+#include "threadsafety.h"
+// Template mixin that adds -Wthread-safety locking annotations to a
+// subset of the mutex API.
+template <typename PARENT>
+class LOCKABLE AnnotatedMixin : public PARENT
+{
+public:
+ void lock() EXCLUSIVE_LOCK_FUNCTION()
+ {
+ PARENT::lock();
+ }
+ void unlock() UNLOCK_FUNCTION()
+ {
+ PARENT::unlock();
+ }
+ bool try_lock() EXCLUSIVE_TRYLOCK_FUNCTION(true)
+ {
+ return PARENT::try_lock();
+ }
+};
/** Wrapped boost mutex: supports recursive locking, but no waiting */
-typedef boost::recursive_mutex CCriticalSection;
+// TODO: We should move away from using the recursive lock by default.
+typedef AnnotatedMixin<boost::recursive_mutex> CCriticalSection;
/** Wrapped boost mutex: supports waiting but not recursive locking */
-typedef boost::mutex CWaitableCriticalSection;
+typedef AnnotatedMixin<boost::mutex> CWaitableCriticalSection;
#ifdef DEBUG_LOCKORDER
void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false);