More cleanup

This commit is contained in:
Patrick 2023-02-09 09:57:23 +01:00
parent 2a762d216d
commit 67edbd8be6
Signed by: mewin
GPG Key ID: CEDB412C39B5BC47
3 changed files with 16 additions and 5 deletions

View File

@ -68,6 +68,8 @@ struct TaskDebugStackFormatter
return std::string((long long)in_indent * 2, ' ');
}
};
#if SQUID_ENABLE_TASK_DEBUG
static std::string FormatDebugString(std::string in_str)
{
std::replace(in_str.begin(), in_str.end(), '\n', ' ');
@ -75,7 +77,6 @@ static std::string FormatDebugString(std::string in_str)
}
//--- SetDebugName Awaiter ---//
#if SQUID_ENABLE_TASK_DEBUG
struct SetDebugName
{
// Sets a Task's debug name field

View File

@ -265,12 +265,12 @@ public:
return *this;
}
template<typename tOtherRet, eTaskRef OtherRefType, eTaskResumable OtherResumable>
bool operator ==(const Task<tOtherRet, OtherRefType, OtherResumable>& in_otherTask) noexcept
bool operator ==(const Task<tOtherRet, OtherRefType, OtherResumable>& in_otherTask) const noexcept
{
return m_taskInternal == in_otherTask.m_taskInternal;
}
template<typename tOtherRet, eTaskRef OtherRefType, eTaskResumable OtherResumable>
bool operator !=(const Task<tOtherRet, OtherRefType, OtherResumable>& in_otherTask) noexcept
bool operator !=(const Task<tOtherRet, OtherRefType, OtherResumable>& in_otherTask) const noexcept
{
return m_taskInternal != in_otherTask.m_taskInternal;
}
@ -343,7 +343,7 @@ public:
{
return ""; // Returns an empty string when task debug is disabled
}
[[nodiscard]] std::string GetDebugStack(std::optional<TaskDebugStackFormatter> in_formatter = {}) const /// @private
[[nodiscard]] std::string GetDebugStack([[maybe_unused]] std::optional<TaskDebugStackFormatter> in_formatter = {}) const /// @private
{
return ""; // Returns an empty string when task debug is disabled
}
@ -496,6 +496,16 @@ public:
return StopTaskIf(std::move(*this), in_cancelFn, in_timeout, in_timeFn);
}
Task<tRet> MergeWith(WeakTask&& in_weak)
{
static_assert(IsStrong() && !IsResumable(), "Can only merge a strong, non-resumable and a weak, resumable task.");
assert(in_weak == *this); // can only merge if both refer to the same task
Task<tRet> result_task = in_weak.MoveToTask<tRet, eTaskRef::Strong, eTaskResumable::Yes>();
*this = nullptr;
return result_task;
}
private:
/// @cond
template <typename, eTaskRef, eTaskResumable, typename> friend struct TaskAwaiterBase;

View File

@ -136,7 +136,7 @@ public:
m_tasks.push_back(std::move(in_task));
}
bool IsManagedTask(const WeakTaskHandle& in_task)
bool IsManagedTask(const WeakTaskHandle& in_task) const
{
return std::find(m_strongRefs.begin(), m_strongRefs.end(), in_task) != m_strongRefs.end();
}