aboutsummaryrefslogtreecommitdiff
path: root/src/sync.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2013-11-29 17:25:30 +1000
committerGavin Andresen <gavinandresen@gmail.com>2013-11-29 17:46:19 +1000
commitc649637b6ccb270bd0160163e6e92c1456774286 (patch)
tree9aaf103937dfe8cd11e39be3845cfc8188125000 /src/sync.cpp
parent207cfbfbf1ea21bd6cf8bb905b0908de339ef518 (diff)
mutex debugging routines: LocksHeld() and AssertLockHeld()
Diffstat (limited to 'src/sync.cpp')
-rw-r--r--src/sync.cpp18
1 files changed, 18 insertions, 0 deletions
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 */