Browse Source

Use mutex pointer instead of name for AssertLockHeld

This makes it useable for non-global locks such as the wallet and
keystore locks.
0.10
Wladimir J. van der Laan 11 years ago
parent
commit
19a5676280
  1. 2
      src/main.cpp
  2. 6
      src/sync.cpp
  3. 5
      src/sync.h

2
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) bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp)
{ {
AssertLockHeld("cs_main"); AssertLockHeld(cs_main);
// Check for duplicate // Check for duplicate
uint256 hash = pblock->GetHash(); uint256 hash = pblock->GetHash();

6
src/sync.cpp

@ -136,11 +136,11 @@ std::string LocksHeld()
return result; 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) BOOST_FOREACH(const PAIRTYPE(void*, CLockLocation)&i, *lockstack)
if (i.second.MutexName() == strName) return; if (i.first == cs) return;
LogPrintf("Lock %s not held; locks held:\n%s", strName.c_str(), LocksHeld().c_str()); LogPrintf("Lock %s not held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld().c_str());
assert(0); assert(0);
} }

5
src/sync.h

@ -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 EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false);
void LeaveCritical(); void LeaveCritical();
std::string LocksHeld(); std::string LocksHeld();
void AssertLockHeld(std::string strName); void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void *cs);
#else #else
void static inline EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false) {} void static inline EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false) {}
void static inline LeaveCritical() {} 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 #endif
#define AssertLockHeld(cs) AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs)
#ifdef DEBUG_LOCKCONTENTION #ifdef DEBUG_LOCKCONTENTION
void PrintLockContention(const char* pszName, const char* pszFile, int nLine); void PrintLockContention(const char* pszName, const char* pszFile, int nLine);

Loading…
Cancel
Save