diff options
| author | Alexander Kjeldaas <[email protected]> | 2012-11-10 23:50:26 -0300 |
|---|---|---|
| committer | Alexander Kjeldaas <[email protected]> | 2012-11-11 00:55:48 -0300 |
| commit | 05f97d1263540b5f9faae971374a25ddc3f6dadb (patch) | |
| tree | 4d17601b5192ab15a51eaf5506a4c730fdb53704 /src | |
| parent | o Added threadsafety.h - a set of macros using the -Wthread-safety (diff) | |
| download | discoin-05f97d1263540b5f9faae971374a25ddc3f6dadb.tar.xz discoin-05f97d1263540b5f9faae971374a25ddc3f6dadb.zip | |
o Added AnnotatedMixin which adds locking annotations to the mutex
API, compatible with clang's -Wthread-safety
Diffstat (limited to 'src')
| -rw-r--r-- | src/sync.h | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/sync.h b/src/sync.h index e80efbe00..b9c89027b 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); |