Skip to content

Commit

Permalink
Use mutex pointer instead of name for AssertLockHeld
Browse files Browse the repository at this point in the history
This makes it useable for non-global locks such as the wallet and
keystore locks.
  • Loading branch information
laanwj committed Dec 19, 2013
1 parent 636a42b commit 19a5676
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main.cpp
Expand Up @@ -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();
Expand Down
6 changes: 3 additions & 3 deletions src/sync.cpp
Expand Up @@ -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);
}

Expand Down
5 changes: 3 additions & 2 deletions src/sync.h
Expand Up @@ -88,12 +88,13 @@ typedef AnnotatedMixin<boost::mutex> 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);
Expand Down

0 comments on commit 19a5676

Please sign in to comment.