Implemented releasing of weak tasks.

This commit is contained in:
Patrick 2023-02-07 18:10:58 +01:00
parent 10dc3c3e54
commit 2a762d216d
Signed by: mewin
GPG Key ID: CEDB412C39B5BC47

View File

@ -136,6 +136,23 @@ public:
m_tasks.push_back(std::move(in_task));
}
bool IsManagedTask(const WeakTaskHandle& in_task)
{
return std::find(m_strongRefs.begin(), m_strongRefs.end(), in_task) != m_strongRefs.end();
}
WeakTask ReleaseWeakTask(const WeakTaskHandle& in_task)
{
assert(!IsManagedTask(in_task));
auto itWeak = std::find(m_tasks.begin(), m_tasks.end(), in_task);
assert(itWeak != m_tasks.end());
WeakTask task = std::move(*itWeak);
*itWeak = nullptr; // otherwise the next line will kill the task (in destructor)
m_tasks.erase(itWeak);
return task;
}
Task<> ReleaseManagedTask(const WeakTaskHandle& in_task)
{
auto itWeak = std::find(m_tasks.begin(), m_tasks.end(), in_task);