aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2011-09-02 12:01:42 -0400
committerGavin Andresen <gavinandresen@gmail.com>2011-09-02 12:01:42 -0400
commitc591cc50eb126eddc78525dd386ea98abaaed724 (patch)
treed93d32e7d3b0cf6d932d6b44ab461ffc54f0854b /src/util.cpp
parentfb45259967032d409bca4d542b55414a7c522fba (diff)
If compiled -DDEBUG_LOCKORDER and run with -debug, print out every mutex lock/unlock (helpful for debugging something-is-holding-a-mutex-too-long problems)
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp26
1 files changed, 20 insertions, 6 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 390b3a340b..76a2700271 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -923,16 +923,22 @@ string FormatFullVersion()
struct CLockLocation
{
- std::string mutexName;
- std::string sourceFile;
- int sourceLine;
-
CLockLocation(const char* pszName, const char* pszFile, int nLine)
{
mutexName = pszName;
sourceFile = pszFile;
sourceLine = nLine;
}
+
+ std::string ToString() const
+ {
+ return mutexName+" "+sourceFile+":"+itostr(sourceLine);
+ }
+
+private:
+ std::string mutexName;
+ std::string sourceFile;
+ int sourceLine;
};
typedef std::vector< std::pair<CCriticalSection*, CLockLocation> > LockStack;
@@ -950,14 +956,14 @@ static void potential_deadlock_detected(const std::pair<CCriticalSection*, CCrit
{
if (i.first == mismatch.first) printf(" (1)");
if (i.first == mismatch.second) printf(" (2)");
- printf(" %s %s:%d\n", i.second.mutexName.c_str(), i.second.sourceFile.c_str(), i.second.sourceLine);
+ printf(" %s\n", i.second.ToString().c_str());
}
printf("Current lock order is:\n");
BOOST_FOREACH(const PAIRTYPE(CCriticalSection*, CLockLocation)& i, s1)
{
if (i.first == mismatch.first) printf(" (1)");
if (i.first == mismatch.second) printf(" (2)");
- printf(" %s %s:%d\n", i.second.mutexName.c_str(), i.second.sourceFile.c_str(), i.second.sourceLine);
+ printf(" %s\n", i.second.ToString().c_str());
}
}
@@ -967,6 +973,7 @@ static void push_lock(CCriticalSection* c, const CLockLocation& locklocation)
if (lockstack.get() == NULL)
lockstack.reset(new LockStack);
+ if (fDebug) printf("Locking: %s\n", locklocation.ToString().c_str());
dd_mutex.lock();
(*lockstack).push_back(std::make_pair(c, locklocation));
@@ -992,7 +999,14 @@ static void push_lock(CCriticalSection* c, const CLockLocation& locklocation)
static void pop_lock()
{
+ if (fDebug)
+ {
+ const CLockLocation& locklocation = (*lockstack).rbegin()->second;
+ printf("Unlocked: %s\n", locklocation.ToString().c_str());
+ }
+ dd_mutex.lock();
(*lockstack).pop_back();
+ dd_mutex.unlock();
}
void CCriticalSection::Enter(const char* pszName, const char* pszFile, int nLine)