X-Git-Url: http://demsky.eecs.uci.edu/git/?a=blobdiff_plain;f=include%2Fllvm%2FSystem%2FMutex.h;h=d2c457dbc91c6d14203295740c6442196d5433a6;hb=ed1c0ffe0b2287deaee7cba7506c93aa34c6d4b7;hp=0003ef881c85d13ddfeafaea4d1f2fe1aeb1617f;hpb=1b19a50cdb292e144ea27bef1cd135efaa6548df;p=oota-llvm.git diff --git a/include/llvm/System/Mutex.h b/include/llvm/System/Mutex.h index 0003ef881c8..d2c457dbc91 100644 --- a/include/llvm/System/Mutex.h +++ b/include/llvm/System/Mutex.h @@ -15,6 +15,7 @@ #define LLVM_SYSTEM_MUTEX_H #include "llvm/System/Threading.h" +#include namespace llvm { @@ -85,18 +86,32 @@ namespace llvm /// running in multithreaded mode. template class SmartMutex : public MutexImpl { + unsigned acquired; + bool recursive; public: - explicit SmartMutex(bool recursive = true) : MutexImpl(recursive) { } + explicit SmartMutex(bool rec = true) : + MutexImpl(rec), acquired(0), recursive(rec) { } bool acquire() { if (!mt_only || llvm_is_multithreaded()) return MutexImpl::acquire(); + + // Single-threaded debugging code. This would be racy in multithreaded + // mode, but provides not sanity checks in single threaded mode. + assert((recursive || acquired == 0) && "Lock already acquired!!"); + ++acquired; return true; } bool release() { if (!mt_only || llvm_is_multithreaded()) return MutexImpl::release(); + + // Single-threaded debugging code. This would be racy in multithreaded + // mode, but provides not sanity checks in single threaded mode. + assert(((recursive && acquired) || (acquired == 1)) && + "Lock not acquired before release!"); + --acquired; return true; }