Merge pull request #3329 from gavinandresen/syncdebug
mutex debugging routines: LocksHeld() and AssertLockHeld()
This commit is contained in:
commit
a65edb104d
3 changed files with 23 additions and 0 deletions
|
@ -2176,6 +2176,8 @@ 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");
|
||||||
|
|
||||||
// Check for duplicate
|
// Check for duplicate
|
||||||
uint256 hash = pblock->GetHash();
|
uint256 hash = pblock->GetHash();
|
||||||
if (mapBlockIndex.count(hash))
|
if (mapBlockIndex.count(hash))
|
||||||
|
|
18
src/sync.cpp
18
src/sync.cpp
|
@ -42,6 +42,8 @@ struct CLockLocation
|
||||||
return mutexName+" "+sourceFile+":"+itostr(sourceLine);
|
return mutexName+" "+sourceFile+":"+itostr(sourceLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string MutexName() const { return mutexName; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string mutexName;
|
std::string mutexName;
|
||||||
std::string sourceFile;
|
std::string sourceFile;
|
||||||
|
@ -126,4 +128,20 @@ void LeaveCritical()
|
||||||
pop_lock();
|
pop_lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string LocksHeld()
|
||||||
|
{
|
||||||
|
std::string result;
|
||||||
|
BOOST_FOREACH(const PAIRTYPE(void*, CLockLocation)&i, *lockstack)
|
||||||
|
result += i.second.ToString() + std::string("\n");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssertLockHeld(std::string strName)
|
||||||
|
{
|
||||||
|
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());
|
||||||
|
assert(0);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* DEBUG_LOCKORDER */
|
#endif /* DEBUG_LOCKORDER */
|
||||||
|
|
|
@ -87,9 +87,12 @@ typedef AnnotatedMixin<boost::mutex> CWaitableCriticalSection;
|
||||||
#ifdef DEBUG_LOCKORDER
|
#ifdef DEBUG_LOCKORDER
|
||||||
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();
|
||||||
|
void AssertLockHeld(std::string strName);
|
||||||
#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) {}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG_LOCKCONTENTION
|
#ifdef DEBUG_LOCKCONTENTION
|
||||||
|
|
Loading…
Add table
Reference in a new issue