Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
brakmic committed Jul 23, 2017
2 parents b6531e9 + a7bbc12 commit 01b9485
Showing 1 changed file with 49 additions and 13 deletions.
62 changes: 49 additions & 13 deletions src/sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,57 @@ static boost::thread_specific_ptr<LockStack> lockstack;

static void potential_deadlock_detected(const std::pair<void*, void*>& mismatch, const LockStack& s1, const LockStack& s2)
{
LogPrintf("POTENTIAL DEADLOCK DETECTED\n");
LogPrintf("Previous lock order was:\n");
BOOST_FOREACH(const PAIRTYPE(void*, CLockLocation)& i, s2)
{
if (i.first == mismatch.first) LogPrintf(" (1)");
if (i.first == mismatch.second) LogPrintf(" (2)");
LogPrintf(" %s\n", i.second.ToString());
// We attempt to not assert on probably-not deadlocks by assuming that
// a try lock will immediately have otherwise bailed if it had
// failed to get the lock
// We do this by, for the locks which triggered the potential deadlock,
// in either lockorder, checking that the second of the two which is locked
// is only a TRY_LOCK, ignoring locks if they are reentrant.
bool firstLocked = false;
bool secondLocked = false;
bool onlyMaybeDeadlock = false;
std::string strOutput = "";

strOutput += "POTENTIAL DEADLOCK DETECTED\n";
strOutput += "Previous lock order was:\n";
BOOST_FOREACH (const PAIRTYPE(void*, CLockLocation) & i, s2) {
if (i.first == mismatch.first) {
strOutput += " (1)";
if (!firstLocked && secondLocked && i.second.fTry)
onlyMaybeDeadlock = true;
firstLocked = true;
}
if (i.first == mismatch.second) {
strOutput += " (2)";
if (!secondLocked && firstLocked && i.second.fTry)
onlyMaybeDeadlock = true;
secondLocked = true;
}
strOutput += strprintf(" %s\n", i.second.ToString().c_str());
}
LogPrintf("Current lock order is:\n");
BOOST_FOREACH(const PAIRTYPE(void*, CLockLocation)& i, s1)
{
if (i.first == mismatch.first) LogPrintf(" (1)");
if (i.first == mismatch.second) LogPrintf(" (2)");
LogPrintf(" %s\n", i.second.ToString());
firstLocked = false;
secondLocked = false;
strOutput += "Current lock order is:\n";
BOOST_FOREACH (const PAIRTYPE(void*, CLockLocation) & i, s1) {
if (i.first == mismatch.first) {
strOutput += " (1)";
if (!firstLocked && secondLocked && i.second.fTry)
onlyMaybeDeadlock = true;
firstLocked = true;
}
if (i.first == mismatch.second) {
strOutput += " (2)";
if (!secondLocked && firstLocked && i.second.fTry)
onlyMaybeDeadlock = true;
secondLocked = true;
}
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);
}

static void push_lock(void* c, const CLockLocation& locklocation, bool fTry)
Expand Down

0 comments on commit 01b9485

Please sign in to comment.