From c591cc50eb126eddc78525dd386ea98abaaed724 Mon Sep 17 00:00:00 2001 From: Gavin Andresen Date: Fri, 2 Sep 2011 12:01:42 -0400 Subject: [PATCH] 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) --- src/util.cpp | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/util.cpp b/src/util.cpp index 390b3a34..76a27002 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 > LockStack; @@ -950,14 +956,14 @@ static void potential_deadlock_detected(const std::pairsecond; + 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)