Skip to content

Commit

Permalink
o Added AnnotatedMixin which adds locking annotations to the mutex
Browse files Browse the repository at this point in the history
  API, compatible with clang's -Wthread-safety
  • Loading branch information
alexanderkjeldaas authored and mikegogulski committed Dec 26, 2012
1 parent 714fc57 commit e622ef1
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/sync.h
Expand Up @@ -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);
Expand Down

0 comments on commit e622ef1

Please sign in to comment.