aboutsummaryrefslogtreecommitdiff
path: root/src/util.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-04-09 13:25:17 -0700
committerPieter Wuille <pieter.wuille@gmail.com>2012-04-09 13:25:17 -0700
commit1a275bac2b5454ae9d6744f28c29cbf40e2fbf13 (patch)
tree4cf7a1b4001ef82c15f4942f6a495aaf530c7d0e /src/util.cpp
parent1044391135b9d2e309c1e960afc72afa2a7e04f5 (diff)
parentf342dac1cb06d5b0d264fa59e448ef6477ec5b6b (diff)
Merge pull request #1052 from sipa/scopedlocks
Use scoped locks instead of CRITICAL_BLOCK
Diffstat (limited to 'src/util.cpp')
-rw-r--r--src/util.cpp24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/util.cpp b/src/util.cpp
index 70f429b7fc..19538a4fa1 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -196,8 +196,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)
@@ -1120,25 +1120,25 @@ private:
int sourceLine;
};
-typedef std::vector< std::pair<CCriticalSection*, CLockLocation> > LockStack;
+typedef std::vector< std::pair<void*, CLockLocation> > LockStack;
static boost::interprocess::interprocess_mutex dd_mutex;
-static std::map<std::pair<CCriticalSection*, CCriticalSection*>, LockStack> lockorders;
+static std::map<std::pair<void*, void*>, LockStack> lockorders;
static boost::thread_specific_ptr<LockStack> lockstack;
-static void potential_deadlock_detected(const std::pair<CCriticalSection*, CCriticalSection*>& mismatch, const LockStack& s1, const LockStack& s2)
+static void potential_deadlock_detected(const std::pair<void*, void*>& 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)");
@@ -1146,7 +1146,7 @@ static void potential_deadlock_detected(const std::pair<CCriticalSection*, CCrit
}
}
-static void push_lock(CCriticalSection* c, const CLockLocation& locklocation)
+static void push_lock(void* c, const CLockLocation& locklocation, bool fTry)
{
bool fOrderOK = true;
if (lockstack.get() == NULL)
@@ -1157,16 +1157,16 @@ static void push_lock(CCriticalSection* c, const CLockLocation& locklocation)
(*lockstack).push_back(std::make_pair(c, locklocation));
- BOOST_FOREACH(const PAIRTYPE(CCriticalSection*, CLockLocation)& i, (*lockstack))
+ if (!fTry) BOOST_FOREACH(const PAIRTYPE(void*, CLockLocation)& i, (*lockstack))
{
if (i.first == c) break;
- std::pair<CCriticalSection*, CCriticalSection*> p1 = std::make_pair(i.first, c);
+ std::pair<void*, void*> p1 = std::make_pair(i.first, c);
if (lockorders.count(p1))
continue;
lockorders[p1] = (*lockstack);
- std::pair<CCriticalSection*, CCriticalSection*> p2 = std::make_pair(c, i.first);
+ std::pair<void*, void*> p2 = std::make_pair(c, i.first);
if (lockorders.count(p2))
{
potential_deadlock_detected(p1, lockorders[p2], lockorders[p1]);
@@ -1188,9 +1188,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()