mirror of
https://github.com/kvazar-network/kevacoin.git
synced 2025-01-17 18:40:09 +00:00
Support for parametrized locks in deadlock detector
This commit is contained in:
parent
f8dcd5ca6f
commit
908037fe16
18
src/util.cpp
18
src/util.cpp
@ -1115,25 +1115,25 @@ private:
|
|||||||
int sourceLine;
|
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 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 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("POTENTIAL DEADLOCK DETECTED\n");
|
||||||
printf("Previous lock order was:\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.first) printf(" (1)");
|
||||||
if (i.first == mismatch.second) printf(" (2)");
|
if (i.first == mismatch.second) printf(" (2)");
|
||||||
printf(" %s\n", i.second.ToString().c_str());
|
printf(" %s\n", i.second.ToString().c_str());
|
||||||
}
|
}
|
||||||
printf("Current lock order is:\n");
|
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.first) printf(" (1)");
|
||||||
if (i.first == mismatch.second) printf(" (2)");
|
if (i.first == mismatch.second) printf(" (2)");
|
||||||
@ -1141,7 +1141,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 fOrderOK = true;
|
bool fOrderOK = true;
|
||||||
if (lockstack.get() == NULL)
|
if (lockstack.get() == NULL)
|
||||||
@ -1152,16 +1152,16 @@ static void push_lock(CCriticalSection* c, const CLockLocation& locklocation)
|
|||||||
|
|
||||||
(*lockstack).push_back(std::make_pair(c, locklocation));
|
(*lockstack).push_back(std::make_pair(c, locklocation));
|
||||||
|
|
||||||
BOOST_FOREACH(const PAIRTYPE(CCriticalSection*, CLockLocation)& i, (*lockstack))
|
BOOST_FOREACH(const PAIRTYPE(void*, CLockLocation)& i, (*lockstack))
|
||||||
{
|
{
|
||||||
if (i.first == c) break;
|
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))
|
if (lockorders.count(p1))
|
||||||
continue;
|
continue;
|
||||||
lockorders[p1] = (*lockstack);
|
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))
|
if (lockorders.count(p2))
|
||||||
{
|
{
|
||||||
potential_deadlock_detected(p1, lockorders[p2], lockorders[p1]);
|
potential_deadlock_detected(p1, lockorders[p2], lockorders[p1]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user