aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2013-12-01 17:43:37 -0800
committerGavin Andresen <gavinandresen@gmail.com>2013-12-01 17:43:37 -0800
commita65edb104d0168b55aaa0ebf6fc46c76b0ce288b (patch)
tree7c5ab6747e71cf4ab8cc275a4e6a579f08576d2f /src
parent40ad6e7f35b539d06d328082b17878f18f0fc22e (diff)
parentc649637b6ccb270bd0160163e6e92c1456774286 (diff)
Merge pull request #3329 from gavinandresen/syncdebug
mutex debugging routines: LocksHeld() and AssertLockHeld()
Diffstat (limited to 'src')
-rw-r--r--src/main.cpp2
-rw-r--r--src/sync.cpp18
-rw-r--r--src/sync.h3
3 files changed, 23 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 457fc941e7..eb3af5bea6 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -2176,6 +2176,8 @@ void PushGetBlocks(CNode* pnode, CBlockIndex* pindexBegin, uint256 hashEnd)
bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp)
{
+ AssertLockHeld("cs_main");
+
// Check for duplicate
uint256 hash = pblock->GetHash();
if (mapBlockIndex.count(hash))
diff --git a/src/sync.cpp b/src/sync.cpp
index 33e1219541..9a20c87f88 100644
--- a/src/sync.cpp
+++ b/src/sync.cpp
@@ -42,6 +42,8 @@ struct CLockLocation
return mutexName+" "+sourceFile+":"+itostr(sourceLine);
}
+ std::string MutexName() const { return mutexName; }
+
private:
std::string mutexName;
std::string sourceFile;
@@ -126,4 +128,20 @@ void LeaveCritical()
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 */
diff --git a/src/sync.h b/src/sync.h
index 39f2cb5155..c50abf81b6 100644
--- a/src/sync.h
+++ b/src/sync.h
@@ -87,9 +87,12 @@ typedef AnnotatedMixin<boost::mutex> CWaitableCriticalSection;
#ifdef DEBUG_LOCKORDER
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);
#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) {}
#endif
#ifdef DEBUG_LOCKCONTENTION