diff --git a/include/Private/TaskPrivate.h b/include/Private/TaskPrivate.h index 34e8494..2f4099d 100644 --- a/include/Private/TaskPrivate.h +++ b/include/Private/TaskPrivate.h @@ -140,7 +140,7 @@ auto RemoveStopTask(Task& in_taskToStop) template struct TaskAwaiterBase { - TaskAwaiterBase(const Task& in_task) + TaskAwaiterBase(const Task& /* in_task */) { // 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(); } - auto await_transform(GetStopContext in_awaiter) + auto await_transform(GetStopContext /* in_awaiter */) { struct GetStopContextAwaiter : public std::suspend_never { diff --git a/include/Task.h b/include/Task.h index 4bae066..2d860ed 100644 --- a/include/Task.h +++ b/include/Task.h @@ -26,8 +26,8 @@ #define DEBUG_STR , std::string in_debugStr #define PASS_DEBUG_STR , in_debugStr #define MANUAL_DEBUG_STR(debugStr) , debugStr -#define WaitUntilImpl(...) _WaitUntil(__VA_ARGS__, #__VA_ARGS__) -#define WaitWhileImpl(...) _WaitWhile(__VA_ARGS__, #__VA_ARGS__) +#define WaitUntilImpl(...) WaitUntil_Impl(__VA_ARGS__, #__VA_ARGS__) +#define WaitWhileImpl(...) WaitWhile_Impl(__VA_ARGS__, #__VA_ARGS__) #ifndef IN_DOXYGEN #define WaitUntil(...) WaitUntilImpl(__VA_ARGS__) #define WaitWhile(...) WaitWhileImpl(__VA_ARGS__) @@ -38,8 +38,8 @@ #define PASS_DEBUG_STR #define MANUAL_DEBUG_STR(...) #ifndef IN_DOXYGEN -#define WaitUntil(...) _WaitUntil(__VA_ARGS__) -#define WaitWhile(...) _WaitWhile(__VA_ARGS__) +#define WaitUntil(...) WaitUntil_Impl(__VA_ARGS__) +#define WaitWhile(...) WaitWhile_Impl(__VA_ARGS__) #endif //IN_DOXYGEN #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) struct StopContext { - bool IsStopRequested() const + [[nodiscard]] bool IsStopRequested() const { return *m_isStoppedPtr; } @@ -213,10 +213,8 @@ public: // Prohibit illegal task types static_assert(RefType == eTaskRef::Strong || std::is_void::value, "Illegal task type (cannot combine weak reference type with non-void return type"); - Task() /// Default constructor (constructs an invalid handle) - { - } - Task(nullptr_t) /// Null-pointer 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(std::shared_ptr in_taskInternal) /// @private @@ -240,7 +238,7 @@ public: { // 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 m_taskInternal = nullptr; @@ -248,6 +246,9 @@ public: } 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)"); RemoveRef(); // Remove logical reference from our current internal task m_taskInternal = in_otherTask.m_taskInternal; @@ -280,7 +281,7 @@ public: // If the internal task can never be resumed again, kill it immediately 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(); } @@ -288,11 +289,11 @@ public: { 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; } - 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; } @@ -323,13 +324,13 @@ public: } #if SQUID_ENABLE_TASK_DEBUG - std::string GetDebugName(std::optional in_formatter = {}) const /// Gets this task's debug name (use TASK_NAME to set the debug name) + [[nodiscard]] std::string GetDebugName(std::optional 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]"; auto debugName = IsValid() ? m_taskInternal->GetDebugName() : defaultRetVal; return in_formatter ? in_formatter.value().Format(debugName) : debugName; } - std::string GetDebugStack(std::optional 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 in_formatter = {}) const /// Gets this task's debug stack (use TASK_NAME to set a task's debug name) { if(IsValid()) { @@ -338,11 +339,11 @@ public: return GetDebugName(in_formatter); } #else - std::string GetDebugName(std::optional in_formatter = {}) const /// @private + [[nodiscard]] std::string GetDebugName(std::optional in_formatter = {}) const /// @private { return ""; // Returns an empty string when task debug is disabled } - std::string GetDebugStack(std::optional in_formatter = {}) const /// @private + [[nodiscard]] std::string GetDebugStack(std::optional in_formatter = {}) const /// @private { return ""; // Returns an empty string when task debug is disabled } @@ -507,7 +508,7 @@ private: std::shared_ptr m_taskInternal; // Casts the internal task storage pointer to a concrete (non-TaskInternalBase) pointer - std::shared_ptr GetInternalTask() const + [[nodiscard]] std::shared_ptr GetInternalTask() const { // We can safely downcast from TaskInternalBase to TaskInternal return std::static_pointer_cast(m_taskInternal); @@ -515,7 +516,7 @@ private: // Copy/Move Implementations template - Task CopyToTask() const + [[nodiscard]] Task CopyToTask() const { Task ret; ret.m_taskInternal = m_taskInternal; @@ -663,7 +664,7 @@ struct TaskWrapper { public: TaskWrapper(Task<> in_task) : task(std::move(in_task)) {} - ~TaskWrapper() {} + ~TaskWrapper() = default; Task<> task; template @@ -731,9 +732,9 @@ struct TaskSelectEntry #define TASK_NAME_ENTRIES(name, entries) \ TASK_NAME(name, [entries]() { \ 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 += "`\n"; \ @@ -743,9 +744,9 @@ struct TaskSelectEntry #define TASK_NAME_ENTRIES_ALL(name, entries) \ TASK_NAME(name, [entries]() { \ 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 += "`\n"; \ @@ -817,11 +818,11 @@ Task Select(std::vector> in_entries) 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(); @@ -837,13 +838,13 @@ inline Task<> WaitUntil(tTaskReadyFn in_readyFn) {} inline Task<> WaitWhile(tTaskReadyFn in_readyFn) {} #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; }); 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; }); @@ -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) 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 diff --git a/include/TaskManager.h b/include/TaskManager.h index 545d7c1..652b77c 100644 --- a/include/TaskManager.h +++ b/include/TaskManager.h @@ -102,7 +102,7 @@ public: return taskHandle; } template - SQUID_NODISCARD TaskHandle Run(const Task& in_task) /// @private Illegal copy implementation + SQUID_NODISCARD TaskHandle Run(const Task& /* in_task */) /// @private Illegal copy implementation { static_assert(static_false::value, "Cannot run an unmanaged task by copy (try Run(std::move(task)))"); return {}; @@ -120,7 +120,7 @@ public: return weakTaskHandle; } template - WeakTaskHandle RunManaged(const Task& in_task) /// @private Illegal copy implementation + WeakTaskHandle RunManaged(const Task& /* in_task */) /// @private Illegal copy implementation { static_assert(static_false::value, "Cannot run a managed task by copy (try RunManaged(std::move(task)))"); return {};