From e622ef1e57ed5e3f6d434cd67b231484e6259a61 Mon Sep 17 00:00:00 2001 From: Alexander Kjeldaas Date: Sat, 10 Nov 2012 23:50:26 -0300 Subject: [PATCH] o Added AnnotatedMixin which adds locking annotations to the mutex API, compatible with clang's -Wthread-safety --- src/sync.h | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/sync.h b/src/sync.h index 9dfc6697c6b57..930c9b2b80bb8 100644 --- a/src/sync.h +++ b/src/sync.h @@ -9,15 +9,36 @@ #include #include #include +#include "threadsafety.h" +// Template mixin that adds -Wthread-safety locking annotations to a +// subset of the mutex API. +template +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 CCriticalSection; /** Wrapped boost mutex: supports waiting but not recursive locking */ -typedef boost::mutex CWaitableCriticalSection; +typedef AnnotatedMixin CWaitableCriticalSection; #ifdef DEBUG_LOCKORDER void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false);