Some cleanup for clang/clang-tidy.

This commit is contained in:
Patrick 2023-02-06 18:13:56 +01:00
parent dae28a9db5
commit 10dc3c3e54
Signed by: mewin
GPG Key ID: CEDB412C39B5BC47
3 changed files with 35 additions and 34 deletions

View File

@ -140,7 +140,7 @@ auto RemoveStopTask(Task<tRet, RefType, Resumable>& in_taskToStop)
template <typename tRet, eTaskRef RefType, eTaskResumable Resumable, typename promise_type> template <typename tRet, eTaskRef RefType, eTaskResumable Resumable, typename promise_type>
struct TaskAwaiterBase struct TaskAwaiterBase
{ {
TaskAwaiterBase(const Task<tRet, RefType, Resumable>& in_task) TaskAwaiterBase(const Task<tRet, RefType, Resumable>& /* in_task */)
{ {
// This constructor exists to minimize downstream compile-error spam when co_awaiting a non-copyable Task by copy // This constructor exists to minimize downstream compile-error spam when co_awaiting a non-copyable Task by copy
} }
@ -417,7 +417,7 @@ public:
return std::suspend_never(); return std::suspend_never();
} }
auto await_transform(GetStopContext in_awaiter) auto await_transform(GetStopContext /* in_awaiter */)
{ {
struct GetStopContextAwaiter : public std::suspend_never struct GetStopContextAwaiter : public std::suspend_never
{ {

View File

@ -26,8 +26,8 @@
#define DEBUG_STR , std::string in_debugStr #define DEBUG_STR , std::string in_debugStr
#define PASS_DEBUG_STR , in_debugStr #define PASS_DEBUG_STR , in_debugStr
#define MANUAL_DEBUG_STR(debugStr) , debugStr #define MANUAL_DEBUG_STR(debugStr) , debugStr
#define WaitUntilImpl(...) _WaitUntil(__VA_ARGS__, #__VA_ARGS__) #define WaitUntilImpl(...) WaitUntil_Impl(__VA_ARGS__, #__VA_ARGS__)
#define WaitWhileImpl(...) _WaitWhile(__VA_ARGS__, #__VA_ARGS__) #define WaitWhileImpl(...) WaitWhile_Impl(__VA_ARGS__, #__VA_ARGS__)
#ifndef IN_DOXYGEN #ifndef IN_DOXYGEN
#define WaitUntil(...) WaitUntilImpl(__VA_ARGS__) #define WaitUntil(...) WaitUntilImpl(__VA_ARGS__)
#define WaitWhile(...) WaitWhileImpl(__VA_ARGS__) #define WaitWhile(...) WaitWhileImpl(__VA_ARGS__)
@ -38,8 +38,8 @@
#define PASS_DEBUG_STR #define PASS_DEBUG_STR
#define MANUAL_DEBUG_STR(...) #define MANUAL_DEBUG_STR(...)
#ifndef IN_DOXYGEN #ifndef IN_DOXYGEN
#define WaitUntil(...) _WaitUntil(__VA_ARGS__) #define WaitUntil(...) WaitUntil_Impl(__VA_ARGS__)
#define WaitWhile(...) _WaitWhile(__VA_ARGS__) #define WaitWhile(...) WaitWhile_Impl(__VA_ARGS__)
#endif //IN_DOXYGEN #endif //IN_DOXYGEN
#endif //SQUID_ENABLE_TASK_DEBUG #endif //SQUID_ENABLE_TASK_DEBUG
@ -95,7 +95,7 @@ struct Suspend : public std::suspend_always
/// Context for a task's stop requests (undefined behavior if used after the underlying task is destroyed) /// Context for a task's stop requests (undefined behavior if used after the underlying task is destroyed)
struct StopContext struct StopContext
{ {
bool IsStopRequested() const [[nodiscard]] bool IsStopRequested() const
{ {
return *m_isStoppedPtr; return *m_isStoppedPtr;
} }
@ -213,10 +213,8 @@ public:
// Prohibit illegal task types // Prohibit illegal task types
static_assert(RefType == eTaskRef::Strong || std::is_void<tRet>::value, "Illegal task type (cannot combine weak reference type with non-void return type"); static_assert(RefType == eTaskRef::Strong || std::is_void<tRet>::value, "Illegal task type (cannot combine weak reference type with non-void return type");
Task() /// Default constructor (constructs an invalid handle) Task() = default; /// Default constructor (constructs an invalid handle)
{ Task(std::nullptr_t) /// Null-pointer constructor (constructs an invalid handle)
}
Task(nullptr_t) /// Null-pointer constructor (constructs an invalid handle)
{ {
} }
Task(std::shared_ptr<tTaskInternal> in_taskInternal) /// @private Task(std::shared_ptr<tTaskInternal> in_taskInternal) /// @private
@ -240,7 +238,7 @@ public:
{ {
// NOTE: No need to alter logical reference here (this is a move) // NOTE: No need to alter logical reference here (this is a move)
} }
Task& operator=(nullptr_t) noexcept /// Null-pointer assignment operator (makes the handle invalid) Task& operator=(std::nullptr_t) noexcept /// Null-pointer assignment operator (makes the handle invalid)
{ {
RemoveRef(); // Remove logical reference from old internal task RemoveRef(); // Remove logical reference from old internal task
m_taskInternal = nullptr; m_taskInternal = nullptr;
@ -248,6 +246,9 @@ public:
} }
Task& operator=(const Task& in_otherTask) /// Copy assignment operator (TaskHandle/WeakTaskHandle only) Task& operator=(const Task& in_otherTask) /// Copy assignment operator (TaskHandle/WeakTaskHandle only)
{ {
if (&in_otherTask == this) {
return *this;
}
static_assert(IsCopyable(), "Cannot copy-assign Task/WeakTask (only TaskHandle/WeakTaskHandle)"); static_assert(IsCopyable(), "Cannot copy-assign Task/WeakTask (only TaskHandle/WeakTaskHandle)");
RemoveRef(); // Remove logical reference from our current internal task RemoveRef(); // Remove logical reference from our current internal task
m_taskInternal = in_otherTask.m_taskInternal; m_taskInternal = in_otherTask.m_taskInternal;
@ -280,7 +281,7 @@ public:
// If the internal task can never be resumed again, kill it immediately // If the internal task can never be resumed again, kill it immediately
KillIfResumable(); KillIfResumable();
} }
bool IsValid() const /// Returns whether the underlying coroutine is valid [[nodiscard]] bool IsValid() const /// Returns whether the underlying coroutine is valid
{ {
return m_taskInternal.get(); return m_taskInternal.get();
} }
@ -288,11 +289,11 @@ public:
{ {
return IsValid(); return IsValid();
} }
bool IsDone() const /// Returns whether the task has terminated [[nodiscard]] bool IsDone() const /// Returns whether the task has terminated
{ {
return IsValid() ? m_taskInternal->IsDone() : true; return IsValid() ? m_taskInternal->IsDone() : true;
} }
bool IsStopRequested() const /// Returns whether a stop request has been issued for the task [[nodiscard]] bool IsStopRequested() const /// Returns whether a stop request has been issued for the task
{ {
return IsValid() ? m_taskInternal->IsStopRequested() : true; return IsValid() ? m_taskInternal->IsStopRequested() : true;
} }
@ -323,13 +324,13 @@ public:
} }
#if SQUID_ENABLE_TASK_DEBUG #if SQUID_ENABLE_TASK_DEBUG
std::string GetDebugName(std::optional<TaskDebugStackFormatter> in_formatter = {}) const /// Gets this task's debug name (use TASK_NAME to set the debug name) [[nodiscard]] std::string GetDebugName(std::optional<TaskDebugStackFormatter> in_formatter = {}) const /// Gets this task's debug name (use TASK_NAME to set the debug name)
{ {
const char* defaultRetVal = Resumable == eTaskResumable::Yes ? "[empty task]" : "[empty task handle]"; const char* defaultRetVal = Resumable == eTaskResumable::Yes ? "[empty task]" : "[empty task handle]";
auto debugName = IsValid() ? m_taskInternal->GetDebugName() : defaultRetVal; auto debugName = IsValid() ? m_taskInternal->GetDebugName() : defaultRetVal;
return in_formatter ? in_formatter.value().Format(debugName) : debugName; return in_formatter ? in_formatter.value().Format(debugName) : debugName;
} }
std::string GetDebugStack(std::optional<TaskDebugStackFormatter> in_formatter = {}) const /// Gets this task's debug stack (use TASK_NAME to set a task's debug name) [[nodiscard]] std::string GetDebugStack(std::optional<TaskDebugStackFormatter> in_formatter = {}) const /// Gets this task's debug stack (use TASK_NAME to set a task's debug name)
{ {
if(IsValid()) if(IsValid())
{ {
@ -338,11 +339,11 @@ public:
return GetDebugName(in_formatter); return GetDebugName(in_formatter);
} }
#else #else
std::string GetDebugName(std::optional<TaskDebugStackFormatter> in_formatter = {}) const /// @private [[nodiscard]] std::string GetDebugName(std::optional<TaskDebugStackFormatter> in_formatter = {}) const /// @private
{ {
return ""; // Returns an empty string when task debug is disabled return ""; // Returns an empty string when task debug is disabled
} }
std::string GetDebugStack(std::optional<TaskDebugStackFormatter> in_formatter = {}) const /// @private [[nodiscard]] std::string GetDebugStack(std::optional<TaskDebugStackFormatter> in_formatter = {}) const /// @private
{ {
return ""; // Returns an empty string when task debug is disabled return ""; // Returns an empty string when task debug is disabled
} }
@ -507,7 +508,7 @@ private:
std::shared_ptr<TaskInternalBase> m_taskInternal; std::shared_ptr<TaskInternalBase> m_taskInternal;
// Casts the internal task storage pointer to a concrete (non-TaskInternalBase) pointer // Casts the internal task storage pointer to a concrete (non-TaskInternalBase) pointer
std::shared_ptr<tTaskInternal> GetInternalTask() const [[nodiscard]] std::shared_ptr<tTaskInternal> GetInternalTask() const
{ {
// We can safely downcast from TaskInternalBase to TaskInternal<void> // We can safely downcast from TaskInternalBase to TaskInternal<void>
return std::static_pointer_cast<tTaskInternal>(m_taskInternal); return std::static_pointer_cast<tTaskInternal>(m_taskInternal);
@ -515,7 +516,7 @@ private:
// Copy/Move Implementations // Copy/Move Implementations
template <typename tNewRet, eTaskRef NewRefType, eTaskResumable NewResumable> template <typename tNewRet, eTaskRef NewRefType, eTaskResumable NewResumable>
Task<tNewRet, NewRefType, NewResumable> CopyToTask() const [[nodiscard]] Task<tNewRet, NewRefType, NewResumable> CopyToTask() const
{ {
Task<tNewRet, NewRefType, NewResumable> ret; Task<tNewRet, NewRefType, NewResumable> ret;
ret.m_taskInternal = m_taskInternal; ret.m_taskInternal = m_taskInternal;
@ -663,7 +664,7 @@ struct TaskWrapper
{ {
public: public:
TaskWrapper(Task<> in_task) : task(std::move(in_task)) {} TaskWrapper(Task<> in_task) : task(std::move(in_task)) {}
~TaskWrapper() {} ~TaskWrapper() = default;
Task<> task; Task<> task;
template <typename tRet> template <typename tRet>
@ -731,9 +732,9 @@ struct TaskSelectEntry
#define TASK_NAME_ENTRIES(name, entries) \ #define TASK_NAME_ENTRIES(name, entries) \
TASK_NAME(name, [entries]() { \ TASK_NAME(name, [entries]() { \
std::string debugStr; \ std::string debugStr; \
for(auto entry : entries) \ for(auto entry : (entries)) \
{ \ { \
debugStr += debugStr.size() ? "\n" : "\n`"; \ debugStr += debugStr.empty() ? "\n`" : "\n"; \
debugStr += entry.taskWrapper->task.GetDebugStack(); \ debugStr += entry.taskWrapper->task.GetDebugStack(); \
} \ } \
debugStr += "`\n"; \ debugStr += "`\n"; \
@ -743,9 +744,9 @@ struct TaskSelectEntry
#define TASK_NAME_ENTRIES_ALL(name, entries) \ #define TASK_NAME_ENTRIES_ALL(name, entries) \
TASK_NAME(name, [entries]() { \ TASK_NAME(name, [entries]() { \
std::string debugStr; \ std::string debugStr; \
for(auto entry : entries) \ for(auto entry : (entries)) \
{ \ { \
debugStr += debugStr.size() ? "\n" : "\n`"; \ debugStr += debugStr.empty() ? "\n`" : "\n"; \
debugStr += entry.taskWrapper->task.GetDebugStack() + (entry.taskWrapper->task.IsDone() ? " [DONE]" : " [RUNNING]"); \ debugStr += entry.taskWrapper->task.GetDebugStack() + (entry.taskWrapper->task.IsDone() ? " [DONE]" : " [RUNNING]"); \
} \ } \
debugStr += "`\n"; \ debugStr += "`\n"; \
@ -817,11 +818,11 @@ Task<tValue> Select(std::vector<TaskSelectEntry<tValue>> in_entries)
while(true) while(true)
{ {
for(size_t i = 0; i < in_entries.size(); ++i) for(size_t idx = 0; idx < in_entries.size(); ++idx)
{ {
if(in_entries[i].Resume() == eTaskStatus::Done) if(in_entries[idx].Resume() == eTaskStatus::Done)
{ {
co_return in_entries[i].GetValue(); co_return in_entries[idx].GetValue();
} }
} }
co_await Suspend(); co_await Suspend();
@ -837,13 +838,13 @@ inline Task<> WaitUntil(tTaskReadyFn in_readyFn) {}
inline Task<> WaitWhile(tTaskReadyFn in_readyFn) {} inline Task<> WaitWhile(tTaskReadyFn in_readyFn) {}
#endif // IN_DOXYGEN #endif // IN_DOXYGEN
inline Task<> _WaitUntil(tTaskReadyFn in_readyFn DEBUG_STR) /// @private inline Task<> WaitUntil_Impl(tTaskReadyFn in_readyFn DEBUG_STR) /// @private
{ {
TASK_NAME("WaitUntil", [debugStr = FormatDebugString(in_debugStr)]{ return debugStr; }); TASK_NAME("WaitUntil", [debugStr = FormatDebugString(in_debugStr)]{ return debugStr; });
co_await in_readyFn; // Wait until the ready functor returns true co_await in_readyFn; // Wait until the ready functor returns true
} }
inline Task<> _WaitWhile(tTaskReadyFn in_readyFn DEBUG_STR) /// @private inline Task<> WaitWhile_Impl(tTaskReadyFn in_readyFn DEBUG_STR) /// @private
{ {
TASK_NAME("WaitWhile", [debugStr = FormatDebugString(in_debugStr)]{ return debugStr; }); TASK_NAME("WaitWhile", [debugStr = FormatDebugString(in_debugStr)]{ return debugStr; });
@ -853,7 +854,7 @@ inline Task<> _WaitWhile(tTaskReadyFn in_readyFn DEBUG_STR) /// @private
/// Awaiter function that waits forever (only for use in tasks that will be killed externally) /// Awaiter function that waits forever (only for use in tasks that will be killed externally)
inline Task<> WaitForever() inline Task<> WaitForever()
{ {
return _WaitUntil([]() { return false; } MANUAL_DEBUG_STR("WaitForever")); return WaitUntil_Impl([]() { return false; } MANUAL_DEBUG_STR("WaitForever"));
} }
/// Awaiter function that waits N seconds in a given time-stream /// Awaiter function that waits N seconds in a given time-stream

View File

@ -102,7 +102,7 @@ public:
return taskHandle; return taskHandle;
} }
template <typename tRet> template <typename tRet>
SQUID_NODISCARD TaskHandle<tRet> Run(const Task<tRet>& in_task) /// @private Illegal copy implementation SQUID_NODISCARD TaskHandle<tRet> Run(const Task<tRet>& /* in_task */) /// @private Illegal copy implementation
{ {
static_assert(static_false<tRet>::value, "Cannot run an unmanaged task by copy (try Run(std::move(task)))"); static_assert(static_false<tRet>::value, "Cannot run an unmanaged task by copy (try Run(std::move(task)))");
return {}; return {};
@ -120,7 +120,7 @@ public:
return weakTaskHandle; return weakTaskHandle;
} }
template <typename tRet> template <typename tRet>
WeakTaskHandle RunManaged(const Task<tRet>& in_task) /// @private Illegal copy implementation WeakTaskHandle RunManaged(const Task<tRet>& /* in_task */) /// @private Illegal copy implementation
{ {
static_assert(static_false<tRet>::value, "Cannot run a managed task by copy (try RunManaged(std::move(task)))"); static_assert(static_false<tRet>::value, "Cannot run a managed task by copy (try RunManaged(std::move(task)))");
return {}; return {};