Use optional for type-safe retval
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <iostream>
|
||||
#include <optional>
|
||||
#include <componentThread.h>
|
||||
#include <lockSet.h>
|
||||
#include <asynchronousContinuation.h>
|
||||
@@ -79,9 +80,12 @@ public:
|
||||
invocationTarget(std::move(invocationTarget))
|
||||
{
|
||||
#ifdef CONFIG_ENABLE_DEBUG_LOCKS
|
||||
if (traceContinuationHistoryForDeadlock())
|
||||
std::optional<std::reference_wrapper<Qutex>> firstFailedQutex =
|
||||
traceContinuationHistoryForDeadlock();
|
||||
|
||||
if (firstFailedQutex.has_value())
|
||||
{
|
||||
handleDeadlock();
|
||||
handleDeadlock(firstFailedQutex.value().get());
|
||||
throw std::runtime_error(
|
||||
"LockerAndInvoker::LockerAndInvoker(): Deadlock detected");
|
||||
}
|
||||
@@ -308,7 +312,8 @@ public:
|
||||
};
|
||||
|
||||
bool traceContinuationHistoryForDeadlockOn(Qutex &firstFailedQutex);
|
||||
bool traceContinuationHistoryForDeadlock(void)
|
||||
std::optional<std::reference_wrapper<Qutex>>
|
||||
traceContinuationHistoryForDeadlock(void)
|
||||
{
|
||||
for (auto& lockUsageDesc
|
||||
: serializedContinuation.requiredLocks.locks)
|
||||
@@ -316,10 +321,10 @@ public:
|
||||
if (traceContinuationHistoryForDeadlockOn(
|
||||
lockUsageDesc.first.get()))
|
||||
{
|
||||
return true;
|
||||
return std::ref(lockUsageDesc.first.get());
|
||||
}
|
||||
}
|
||||
return false;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user