LockSet:tryAcquireOrBackoff use optional<ref_wrapper<Qutex>>

Replace the previous Qutex** raw pointer with a std::optional.
This commit is contained in:
2025-09-30 10:36:19 -04:00
parent e3ce533fe4
commit f15c07bc83
3 changed files with 10 additions and 10 deletions
+4 -1
View File
@@ -7,6 +7,7 @@
#include <stdexcept>
#include <utility>
#include <memory>
#include <optional>
#include <qutex.h>
#include <lockerAndInvokerBase.h>
@@ -85,7 +86,9 @@ public:
* @return true if all locks were acquired, false otherwise
*/
bool tryAcquireOrBackOff(
LockerAndInvokerBase &lockvoker, Qutex **firstFailedQutex = nullptr);
LockerAndInvokerBase &lockvoker,
std::optional<std::reference_wrapper<Qutex>> &firstFailedQutex
= std::nullopt);
void unregisterFromQutexQueues();
// @brief Release all locks
+3 -5
View File
@@ -107,14 +107,12 @@ public:
"executing on wrong ComponentThread");
}
Qutex *firstFailedQutexPtr = nullptr;
std::optional<std::reference_wrapper<Qutex>> firstFailedQutexRet;
bool deadlockLikely = isDeadlockLikely();
bool gridlockLikely = isGridlockLikely();
if (!serializedContinuation.requiredLocks.tryAcquireOrBackOff(
*this,
((deadlockLikely || gridlockLikely)
? &firstFailedQutexPtr : nullptr)))
*this, firstFailedQutexRet))
{
// Just allow this lockvoker to be dropped from its io_service.
allowAwakening();
@@ -122,7 +120,7 @@ public:
{ return; }
#ifdef CONFIG_ENABLE_DEBUG_LOCKS
Qutex &firstFailedQutex = *firstFailedQutexPtr;
Qutex &firstFailedQutex = firstFailedQutexRet.value().get();
bool isDeadlock = traceContinuationHistoryForDeadlockOn(
firstFailedQutex);
+3 -4
View File
@@ -44,7 +44,8 @@ void LockSet<OriginalCbFnT>::registerInQutexQueues(
template <class OriginalCbFnT>
bool LockSet<OriginalCbFnT>::tryAcquireOrBackOff(
LockerAndInvokerBase &lockvoker, Qutex **firstFailedQutex
LockerAndInvokerBase &lockvoker,
std::optional<std::reference_wrapper<Qutex>> &firstFailedQutex
)
{
if (!registeredInQutexQueues)
@@ -71,9 +72,7 @@ bool LockSet<OriginalCbFnT>::tryAcquireOrBackOff(
lockvoker, nRequiredLocks))
{
// Set the first failed qutex for debugging
if (firstFailedQutex) {
*firstFailedQutex = &lockUsageDesc.first.get();
}
firstFailedQutex = std::ref(lockUsageDesc.first.get());
break;
}