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