From 19a5676280370148492cf59a5103584cf37893ac Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Thu, 19 Dec 2013 09:09:51 +0100 Subject: [PATCH] Use mutex pointer instead of name for AssertLockHeld This makes it useable for non-global locks such as the wallet and keystore locks. --- src/main.cpp | 2 +- src/sync.cpp | 6 +++--- src/sync.h | 5 +++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index d130e9705..174c99345 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2238,7 +2238,7 @@ void PushGetBlocks(CNode* pnode, CBlockIndex* pindexBegin, uint256 hashEnd) bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp) { - AssertLockHeld("cs_main"); + AssertLockHeld(cs_main); // Check for duplicate uint256 hash = pblock->GetHash(); diff --git a/src/sync.cpp b/src/sync.cpp index 9a20c87f8..b57d8c3c0 100644 --- a/src/sync.cpp +++ b/src/sync.cpp @@ -136,11 +136,11 @@ std::string LocksHeld() return result; } -void AssertLockHeld(std::string strName) +void AssertLockHeldInternal(const char *pszName, const char* pszFile, int nLine, void *cs) { BOOST_FOREACH(const PAIRTYPE(void*, CLockLocation)&i, *lockstack) - if (i.second.MutexName() == strName) return; - LogPrintf("Lock %s not held; locks held:\n%s", strName.c_str(), LocksHeld().c_str()); + if (i.first == cs) return; + LogPrintf("Lock %s not held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld().c_str()); assert(0); } diff --git a/src/sync.h b/src/sync.h index c50abf81b..077ed59b8 100644 --- a/src/sync.h +++ b/src/sync.h @@ -88,12 +88,13 @@ typedef AnnotatedMixin CWaitableCriticalSection; void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false); void LeaveCritical(); std::string LocksHeld(); -void AssertLockHeld(std::string strName); +void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void *cs); #else void static inline EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false) {} void static inline LeaveCritical() {} -void static inline AssertLockHeld(std::string) {} +void static inline AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void *cs) {} #endif +#define AssertLockHeld(cs) AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs) #ifdef DEBUG_LOCKCONTENTION void PrintLockContention(const char* pszName, const char* pszFile, int nLine);