mirror of
https://github.com/latentPrion/libspinscale.git
synced 2026-04-17 22:44:25 +00:00
Dbg:traceContinHistForDeadlock: consult LockUsageDesc::hasBeenReleased
Don't raise the alarm for a deadlock if the lock has already been released at the moment of checking.
This commit is contained in:
@@ -197,15 +197,52 @@ public:
|
||||
allLocksAcquired = false;
|
||||
}
|
||||
|
||||
const LockUsageDesc &getLockUsageDesc(const Qutex &criterionLock) const
|
||||
std::optional<std::reference_wrapper<LockUsageDesc>>
|
||||
findLockUsageDesc(const Qutex &criterionLock)
|
||||
{
|
||||
for (auto& lockUsageDesc : locks)
|
||||
{
|
||||
if (&lockUsageDesc.qutex.get() == &criterionLock) {
|
||||
return lockUsageDesc;
|
||||
return std::ref(lockUsageDesc);
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::optional<std::reference_wrapper<const LockUsageDesc>>
|
||||
findLockUsageDesc(const Qutex &criterionLock) const
|
||||
{
|
||||
for (const auto& lockUsageDesc : locks)
|
||||
{
|
||||
if (&lockUsageDesc.qutex.get() == &criterionLock) {
|
||||
return std::cref(lockUsageDesc);
|
||||
}
|
||||
}
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
LockUsageDesc &getLockUsageDesc(const Qutex &criterionLock)
|
||||
{
|
||||
auto lockUsageDesc = findLockUsageDesc(criterionLock);
|
||||
if (lockUsageDesc.has_value()) {
|
||||
return lockUsageDesc->get();
|
||||
}
|
||||
|
||||
// Should never happen if the LockSet is properly constructed
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) +
|
||||
": Qutex not found in this LockSet");
|
||||
}
|
||||
|
||||
const LockUsageDesc &getLockUsageDesc(const Qutex &criterionLock) const
|
||||
{
|
||||
auto lockUsageDesc = findLockUsageDesc(criterionLock);
|
||||
if (lockUsageDesc.has_value()) {
|
||||
return lockUsageDesc->get();
|
||||
}
|
||||
|
||||
// Should never happen if the LockSet is properly constructed
|
||||
throw std::runtime_error(
|
||||
std::string(__func__) +
|
||||
@@ -225,8 +262,7 @@ public:
|
||||
": LockSet::releaseQutexEarly() called but allLocksAcquired is false");
|
||||
}
|
||||
|
||||
auto& lockUsageDesc = const_cast<LockUsageDesc&>(
|
||||
getLockUsageDesc(qutex));
|
||||
auto& lockUsageDesc = getLockUsageDesc(qutex);
|
||||
|
||||
if (!lockUsageDesc.hasBeenReleased)
|
||||
{
|
||||
|
||||
@@ -335,11 +335,12 @@ SerializedAsynchronousContinuation<OriginalCbFnT>
|
||||
auto heldLockSet = currContin->getLockSet();
|
||||
if (!heldLockSet.has_value()) { continue; }
|
||||
|
||||
// Check if the firstFailedQutex is in this continuation's LockSet
|
||||
try {
|
||||
heldLockSet->get().getLockUsageDesc(firstFailedQutex);
|
||||
} catch (const std::runtime_error& e) {
|
||||
std::cerr << __func__ << ": " << e.what() << std::endl;
|
||||
// A miss is expected here; only a hit indicates a potential deadlock.
|
||||
auto lockUsageDesc = heldLockSet->get().findLockUsageDesc(
|
||||
firstFailedQutex);
|
||||
if (!lockUsageDesc.has_value()
|
||||
|| lockUsageDesc->get().hasBeenReleased)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -434,10 +435,10 @@ SerializedAsynchronousContinuation<OriginalCbFnT>
|
||||
auto heldLockSet = currContin->getLockSet();
|
||||
if (!heldLockSet.has_value()) { continue; }
|
||||
|
||||
// Check if this continuation holds the foreign lock
|
||||
try {
|
||||
const auto& lockUsageDesc = heldLockSet
|
||||
->get().getLockUsageDesc(foreignLock);
|
||||
// A miss is expected here; a hit indicates a potential gridlock.
|
||||
auto lockUsageDesc = heldLockSet->get().findLockUsageDesc(
|
||||
foreignLock);
|
||||
if (!lockUsageDesc.has_value()) { continue; }
|
||||
|
||||
// Matched! We hold a lock that the foreign owner is waiting for
|
||||
std::cout << __func__ << ": Gridlock detected: We hold lock @"
|
||||
@@ -449,10 +450,6 @@ SerializedAsynchronousContinuation<OriginalCbFnT>
|
||||
<< std::endl;
|
||||
|
||||
return true;
|
||||
} catch (const std::runtime_error& e) {
|
||||
// This continuation doesn't hold the foreign lock. Continue.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user