diff --git a/include/qutex.h b/include/qutex.h index 7a50573..0a83e79 100644 --- a/include/qutex.h +++ b/include/qutex.h @@ -28,7 +28,7 @@ public: Qutex([[maybe_unused]] const std::string &_name) : #ifdef CONFIG_ENABLE_DEBUG_LOCKS - name(_name), + name(_name), currOwner(nullptr), #endif isOwned(false) {} @@ -92,6 +92,7 @@ public: public: #ifdef CONFIG_ENABLE_DEBUG_LOCKS std::string name; + LockerAndInvokerBase* currOwner; #endif SpinLock lock; LockerAndInvokerBase::List queue; diff --git a/smocore/qutex.cpp b/smocore/qutex.cpp index c96aadc..0939771 100644 --- a/smocore/qutex.cpp +++ b/smocore/qutex.cpp @@ -43,6 +43,9 @@ bool Qutex::tryAcquire( if (qNItems == 1 || nRearItemsToScan < 1) { isOwned = true; +#ifdef CONFIG_ENABLE_DEBUG_LOCKS + currOwner = const_cast(&tryingLockvoker); +#endif lock.release(); return true; } @@ -55,6 +58,9 @@ bool Qutex::tryAcquire( if ((*queue.front()) == tryingLockvoker) { isOwned = true; +#ifdef CONFIG_ENABLE_DEBUG_LOCKS + currOwner = const_cast(&tryingLockvoker); +#endif ret = true; } else { @@ -89,6 +95,9 @@ bool Qutex::tryAcquire( // Not found in rear portion - must be in top X%, so succeed isOwned = true; +#ifdef CONFIG_ENABLE_DEBUG_LOCKS + currOwner = const_cast(&tryingLockvoker); +#endif lock.release(); return true; } @@ -220,6 +229,9 @@ void Qutex::backoff( } isOwned = false; +#ifdef CONFIG_ENABLE_DEBUG_LOCKS + currOwner = nullptr; +#endif LockerAndInvokerBase &newFront = *queue.front(); lock.release(); @@ -280,6 +292,9 @@ void Qutex::release() lock.acquire(); isOwned = false; +#ifdef CONFIG_ENABLE_DEBUG_LOCKS + currOwner = nullptr; +#endif // It's possible for there to be 0 items left in queue after unregistering. if (queue.empty())