From f8dcd5ca6f55ad49807cf7491c1f153f6158400e Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 6 Apr 2012 18:39:12 +0200 Subject: Use scoped locks instead of CRITICAL_BLOCK --- src/util.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index d55e7ae10..fd4847b1a 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -195,8 +195,8 @@ inline int OutputDebugStringF(const char* pszFormat, ...) static CCriticalSection cs_OutputDebugStringF; // accumulate a line at a time - CRITICAL_BLOCK(cs_OutputDebugStringF) { + LOCK(cs_OutputDebugStringF); static char pszBuffer[50000]; static char* pend; if (pend == NULL) -- cgit v1.2.3 From 908037fe16843aa354f63af8f14804821aaf70f1 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 7 Apr 2012 18:29:31 +0200 Subject: Support for parametrized locks in deadlock detector --- src/util.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index fd4847b1a..17442a3bc 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1115,25 +1115,25 @@ private: int sourceLine; }; -typedef std::vector< std::pair > LockStack; +typedef std::vector< std::pair > LockStack; static boost::interprocess::interprocess_mutex dd_mutex; -static std::map, LockStack> lockorders; +static std::map, LockStack> lockorders; static boost::thread_specific_ptr lockstack; -static void potential_deadlock_detected(const std::pair& mismatch, const LockStack& s1, const LockStack& s2) +static void potential_deadlock_detected(const std::pair& mismatch, const LockStack& s1, const LockStack& s2) { printf("POTENTIAL DEADLOCK DETECTED\n"); printf("Previous lock order was:\n"); - BOOST_FOREACH(const PAIRTYPE(CCriticalSection*, CLockLocation)& i, s2) + BOOST_FOREACH(const PAIRTYPE(void*, CLockLocation)& i, s2) { if (i.first == mismatch.first) printf(" (1)"); if (i.first == mismatch.second) printf(" (2)"); printf(" %s\n", i.second.ToString().c_str()); } printf("Current lock order is:\n"); - BOOST_FOREACH(const PAIRTYPE(CCriticalSection*, CLockLocation)& i, s1) + BOOST_FOREACH(const PAIRTYPE(void*, CLockLocation)& i, s1) { if (i.first == mismatch.first) printf(" (1)"); if (i.first == mismatch.second) printf(" (2)"); @@ -1141,7 +1141,7 @@ static void potential_deadlock_detected(const std::pair p1 = std::make_pair(i.first, c); + std::pair p1 = std::make_pair(i.first, c); if (lockorders.count(p1)) continue; lockorders[p1] = (*lockstack); - std::pair p2 = std::make_pair(c, i.first); + std::pair p2 = std::make_pair(c, i.first); if (lockorders.count(p2)) { potential_deadlock_detected(p1, lockorders[p2], lockorders[p1]); -- cgit v1.2.3 From f342dac1cb06d5b0d264fa59e448ef6477ec5b6b Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sat, 7 Apr 2012 18:55:29 +0200 Subject: Do not report spurious deadlocks caused by TRY_LOCK --- src/util.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/util.cpp') diff --git a/src/util.cpp b/src/util.cpp index 17442a3bc..affca341c 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1141,7 +1141,7 @@ static void potential_deadlock_detected(const std::pair& mismatch, } } -static void push_lock(void* c, const CLockLocation& locklocation) +static void push_lock(void* c, const CLockLocation& locklocation, bool fTry) { bool fOrderOK = true; if (lockstack.get() == NULL) @@ -1152,7 +1152,7 @@ static void push_lock(void* c, const CLockLocation& locklocation) (*lockstack).push_back(std::make_pair(c, locklocation)); - BOOST_FOREACH(const PAIRTYPE(void*, CLockLocation)& i, (*lockstack)) + if (!fTry) BOOST_FOREACH(const PAIRTYPE(void*, CLockLocation)& i, (*lockstack)) { if (i.first == c) break; @@ -1183,9 +1183,9 @@ static void pop_lock() dd_mutex.unlock(); } -void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs) +void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs, bool fTry) { - push_lock(cs, CLockLocation(pszName, pszFile, nLine)); + push_lock(cs, CLockLocation(pszName, pszFile, nLine), fTry); } void LeaveCritical() -- cgit v1.2.3