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