Skip to content

Commit 19a5676

Browse files
committed
Use mutex pointer instead of name for AssertLockHeld
This makes it useable for non-global locks such as the wallet and keystore locks.
1 parent 636a42b commit 19a5676

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2238,7 +2238,7 @@ void PushGetBlocks(CNode* pnode, CBlockIndex* pindexBegin, uint256 hashEnd)
22382238

22392239
bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp)
22402240
{
2241-
AssertLockHeld("cs_main");
2241+
AssertLockHeld(cs_main);
22422242

22432243
// Check for duplicate
22442244
uint256 hash = pblock->GetHash();

src/sync.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,11 @@ std::string LocksHeld()
136136
return result;
137137
}
138138

139-
void AssertLockHeld(std::string strName)
139+
void AssertLockHeldInternal(const char *pszName, const char* pszFile, int nLine, void *cs)
140140
{
141141
BOOST_FOREACH(const PAIRTYPE(void*, CLockLocation)&i, *lockstack)
142-
if (i.second.MutexName() == strName) return;
143-
LogPrintf("Lock %s not held; locks held:\n%s", strName.c_str(), LocksHeld().c_str());
142+
if (i.first == cs) return;
143+
LogPrintf("Lock %s not held in %s:%i; locks held:\n%s", pszName, pszFile, nLine, LocksHeld().c_str());
144144
assert(0);
145145
}
146146

src/sync.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,13 @@ typedef AnnotatedMixin<boost::mutex> CWaitableCriticalSection;
8888
void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false);
8989
void LeaveCritical();
9090
std::string LocksHeld();
91-
void AssertLockHeld(std::string strName);
91+
void AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void *cs);
9292
#else
9393
void static inline EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry = false) {}
9494
void static inline LeaveCritical() {}
95-
void static inline AssertLockHeld(std::string) {}
95+
void static inline AssertLockHeldInternal(const char* pszName, const char* pszFile, int nLine, void *cs) {}
9696
#endif
97+
#define AssertLockHeld(cs) AssertLockHeldInternal(#cs, __FILE__, __LINE__, &cs)
9798

9899
#ifdef DEBUG_LOCKCONTENTION
99100
void PrintLockContention(const char* pszName, const char* pszFile, int nLine);

0 commit comments

Comments
 (0)