From 2f18ade4abe1b754343b365a04ab8806723e0d0a Mon Sep 17 00:00:00 2001 From: Hayodea Hakol Date: Sat, 27 Sep 2025 21:27:04 -0400 Subject: [PATCH] Locking: pre-emptively detect deadlocks in Lockvoker constructor We can now check for deadlocks both pre-emptively and reactively. We can eventually add function vaddrs and even function names to our tracing code. --- include/serializedAsynchronousContinuation.h | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/include/serializedAsynchronousContinuation.h b/include/serializedAsynchronousContinuation.h index 48d634d..e89730d 100644 --- a/include/serializedAsynchronousContinuation.h +++ b/include/serializedAsynchronousContinuation.h @@ -72,6 +72,15 @@ public: target(target), invocationTarget(std::move(invocationTarget)) { +#ifdef CONFIG_ENABLE_DEBUG_LOCKS + if (traceContinuationHistoryForDeadlock()) + { + handleDeadlock(); + throw std::runtime_error( + "LockerAndInvoker::LockerAndInvoker(): Deadlock detected"); + } +#endif // CONFIG_ENABLE_DEBUG_LOCKS + firstWake(); } @@ -195,6 +204,20 @@ public: #ifdef CONFIG_ENABLE_DEBUG_LOCKS bool traceContinuationHistoryForDeadlockOn(Qutex &firstFailedQutex); + bool traceContinuationHistoryForDeadlock(void) + { + for (auto& lockUsageDesc + : serializedContinuation.requiredLocks.locks) + { + if (traceContinuationHistoryForDeadlockOn( + lockUsageDesc.first.get())) + { + return true; + } + } + return false; + } + /** * @brief Handle a likely deadlock situation by logging debug information * @param firstFailedQutex The first qutex that failed acquisition