Qutex: Add currOwner pointer for debugging

We'll use this to detect gridlock-type deadlocks between
two requests
This commit is contained in:
2025-09-29 12:40:43 -04:00
parent f1ce1ab19c
commit 7e514a1fa3
2 changed files with 17 additions and 1 deletions
+2 -1
View File
@@ -28,7 +28,7 @@ public:
Qutex([[maybe_unused]] const std::string &_name) Qutex([[maybe_unused]] const std::string &_name)
: :
#ifdef CONFIG_ENABLE_DEBUG_LOCKS #ifdef CONFIG_ENABLE_DEBUG_LOCKS
name(_name), name(_name), currOwner(nullptr),
#endif #endif
isOwned(false) isOwned(false)
{} {}
@@ -92,6 +92,7 @@ public:
public: public:
#ifdef CONFIG_ENABLE_DEBUG_LOCKS #ifdef CONFIG_ENABLE_DEBUG_LOCKS
std::string name; std::string name;
LockerAndInvokerBase* currOwner;
#endif #endif
SpinLock lock; SpinLock lock;
LockerAndInvokerBase::List queue; LockerAndInvokerBase::List queue;
+15
View File
@@ -43,6 +43,9 @@ bool Qutex::tryAcquire(
if (qNItems == 1 || nRearItemsToScan < 1) if (qNItems == 1 || nRearItemsToScan < 1)
{ {
isOwned = true; isOwned = true;
#ifdef CONFIG_ENABLE_DEBUG_LOCKS
currOwner = const_cast<LockerAndInvokerBase*>(&tryingLockvoker);
#endif
lock.release(); lock.release();
return true; return true;
} }
@@ -55,6 +58,9 @@ bool Qutex::tryAcquire(
if ((*queue.front()) == tryingLockvoker) if ((*queue.front()) == tryingLockvoker)
{ {
isOwned = true; isOwned = true;
#ifdef CONFIG_ENABLE_DEBUG_LOCKS
currOwner = const_cast<LockerAndInvokerBase*>(&tryingLockvoker);
#endif
ret = true; ret = true;
} }
else { else {
@@ -89,6 +95,9 @@ bool Qutex::tryAcquire(
// Not found in rear portion - must be in top X%, so succeed // Not found in rear portion - must be in top X%, so succeed
isOwned = true; isOwned = true;
#ifdef CONFIG_ENABLE_DEBUG_LOCKS
currOwner = const_cast<LockerAndInvokerBase*>(&tryingLockvoker);
#endif
lock.release(); lock.release();
return true; return true;
} }
@@ -220,6 +229,9 @@ void Qutex::backoff(
} }
isOwned = false; isOwned = false;
#ifdef CONFIG_ENABLE_DEBUG_LOCKS
currOwner = nullptr;
#endif
LockerAndInvokerBase &newFront = *queue.front(); LockerAndInvokerBase &newFront = *queue.front();
lock.release(); lock.release();
@@ -280,6 +292,9 @@ void Qutex::release()
lock.acquire(); lock.acquire();
isOwned = false; isOwned = false;
#ifdef CONFIG_ENABLE_DEBUG_LOCKS
currOwner = nullptr;
#endif
// It's possible for there to be 0 items left in queue after unregistering. // It's possible for there to be 0 items left in queue after unregistering.
if (queue.empty()) if (queue.empty())