diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2012-04-09 13:25:17 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2012-04-09 13:25:17 -0700 |
commit | 1a275bac2b5454ae9d6744f28c29cbf40e2fbf13 (patch) | |
tree | 4cf7a1b4001ef82c15f4942f6a495aaf530c7d0e /src/util.h | |
parent | 1044391135b9d2e309c1e960afc72afa2a7e04f5 (diff) | |
parent | f342dac1cb06d5b0d264fa59e448ef6477ec5b6b (diff) |
Merge pull request #1052 from sipa/scopedlocks
Use scoped locks instead of CRITICAL_BLOCK
Diffstat (limited to 'src/util.h')
-rw-r--r-- | src/util.h | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/src/util.h b/src/util.h index 635790b71b..a04ab2c948 100644 --- a/src/util.h +++ b/src/util.h @@ -190,10 +190,10 @@ typedef boost::interprocess::interprocess_recursive_mutex CCriticalSection; typedef boost::interprocess::interprocess_mutex CWaitableCriticalSection; #ifdef DEBUG_LOCKORDER -void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs); +void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false); void LeaveCritical(); #else -void static inline EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs) {} +void static inline EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false) {} void static inline LeaveCritical() {} #endif @@ -234,7 +234,7 @@ public: { if (!lock.owns()) { - EnterCritical(pszName, pszFile, nLine, (void*)(lock.mutex())); + EnterCritical(pszName, pszFile, nLine, (void*)(lock.mutex()), true); lock.try_lock(); if (!lock.owns()) LeaveCritical(); @@ -282,13 +282,10 @@ typedef boost::interprocess::interprocess_condition CConditionVariable; #define NOTIFY_ALL(name) \ do { (name).notify_all(); } while(0) -#define CRITICAL_BLOCK(cs) \ - for (bool fcriticalblockonce=true; fcriticalblockonce; assert(("break caught by CRITICAL_BLOCK!" && !fcriticalblockonce)), fcriticalblockonce=false) \ - for (CCriticalBlock criticalblock(cs, #cs, __FILE__, __LINE__); fcriticalblockonce; fcriticalblockonce=false) - -#define WAITABLE_CRITICAL_BLOCK(cs) \ - for (bool fcriticalblockonce=true; fcriticalblockonce; assert(("break caught by WAITABLE_CRITICAL_BLOCK!" && !fcriticalblockonce)), fcriticalblockonce=false) \ - for (CWaitableCriticalBlock waitablecriticalblock(cs, #cs, __FILE__, __LINE__); fcriticalblockonce; fcriticalblockonce=false) +#define LOCK(cs) CCriticalBlock criticalblock(cs, #cs, __FILE__, __LINE__) +#define LOCK2(cs1,cs2) CCriticalBlock criticalblock1(cs1, #cs1, __FILE__, __LINE__),criticalblock2(cs2, #cs2, __FILE__, __LINE__) +#define TRY_LOCK(cs,name) CCriticalBlock name(cs, #cs, __FILE__, __LINE__, true) +#define WAITABLE_LOCK(cs) CWaitableCriticalBlock waitablecriticalblock(cs, #cs, __FILE__, __LINE__) #define ENTER_CRITICAL_SECTION(cs) \ { \ @@ -302,10 +299,6 @@ typedef boost::interprocess::interprocess_condition CConditionVariable; LeaveCritical(); \ } -#define TRY_CRITICAL_BLOCK(cs) \ - for (bool fcriticalblockonce=true; fcriticalblockonce; assert(("break caught by TRY_CRITICAL_BLOCK!" && !fcriticalblockonce)), fcriticalblockonce=false) \ - for (CCriticalBlock criticalblock(cs, #cs, __FILE__, __LINE__, true); fcriticalblockonce && (fcriticalblockonce = criticalblock); fcriticalblockonce=false) - // This is exactly like std::string, but with a custom allocator. // (secure_allocator<> is defined in serialize.h) |