Changes in potential_deadlock_detected behavior: (#1259)

1. print to stdout too
2. only print when it's critical (i.e. going to crash on assert)
This commit is contained in:
UdjinM6 2017-01-11 03:00:34 +04:00 committed by GitHub
parent 26419596ce
commit 9114ef7930

View File

@ -72,41 +72,46 @@ static void potential_deadlock_detected(const std::pair<void*, void*>& mismatch,
bool firstLocked = false; bool firstLocked = false;
bool secondLocked = false; bool secondLocked = false;
bool onlyMaybeDeadlock = false; bool onlyMaybeDeadlock = false;
std::string strOutput = "";
LogPrintf("POTENTIAL DEADLOCK DETECTED\n"); strOutput += "POTENTIAL DEADLOCK DETECTED\n";
LogPrintf("Previous lock order was:\n"); strOutput += "Previous lock order was:\n";
BOOST_FOREACH (const PAIRTYPE(void*, CLockLocation) & i, s2) { BOOST_FOREACH (const PAIRTYPE(void*, CLockLocation) & i, s2) {
if (i.first == mismatch.first) { if (i.first == mismatch.first) {
LogPrintf(" (1)"); strOutput += " (1)";
if (!firstLocked && secondLocked && i.second.fTry) if (!firstLocked && secondLocked && i.second.fTry)
onlyMaybeDeadlock = true; onlyMaybeDeadlock = true;
firstLocked = true; firstLocked = true;
} }
if (i.first == mismatch.second) { if (i.first == mismatch.second) {
LogPrintf(" (2)"); strOutput += " (2)";
if (!secondLocked && firstLocked && i.second.fTry) if (!secondLocked && firstLocked && i.second.fTry)
onlyMaybeDeadlock = true; onlyMaybeDeadlock = true;
secondLocked = true; secondLocked = true;
} }
LogPrintf(" %s\n", i.second.ToString()); strOutput += strprintf(" %s\n", i.second.ToString().c_str());
} }
firstLocked = false; firstLocked = false;
secondLocked = false; secondLocked = false;
LogPrintf("Current lock order is:\n"); strOutput += "Current lock order is:\n";
BOOST_FOREACH (const PAIRTYPE(void*, CLockLocation) & i, s1) { BOOST_FOREACH (const PAIRTYPE(void*, CLockLocation) & i, s1) {
if (i.first == mismatch.first) { if (i.first == mismatch.first) {
LogPrintf(" (1)"); strOutput += " (1)";
if (!firstLocked && secondLocked && i.second.fTry) if (!firstLocked && secondLocked && i.second.fTry)
onlyMaybeDeadlock = true; onlyMaybeDeadlock = true;
firstLocked = true; firstLocked = true;
} }
if (i.first == mismatch.second) { if (i.first == mismatch.second) {
LogPrintf(" (2)"); strOutput += " (2)";
if (!secondLocked && firstLocked && i.second.fTry) if (!secondLocked && firstLocked && i.second.fTry)
onlyMaybeDeadlock = true; onlyMaybeDeadlock = true;
secondLocked = true; secondLocked = true;
} }
LogPrintf(" %s\n", i.second.ToString()); strOutput += strprintf(" %s\n", i.second.ToString().c_str());
}
if(!onlyMaybeDeadlock) {
printf("%s\n", strOutput.c_str());
LogPrintf("%s\n", strOutput.c_str());
} }
assert(onlyMaybeDeadlock); assert(onlyMaybeDeadlock);
} }