Added methods for task context switching.
This commit is contained in:
parent
6b93f54653
commit
c8edb195f4
@ -490,6 +490,7 @@ private:
|
|||||||
template <typename, eTaskRef, eTaskResumable, typename> friend struct TaskAwaiterBase;
|
template <typename, eTaskRef, eTaskResumable, typename> friend struct TaskAwaiterBase;
|
||||||
template <typename, eTaskRef, eTaskResumable> friend class Task;
|
template <typename, eTaskRef, eTaskResumable> friend class Task;
|
||||||
friend class TaskInternalBase;
|
friend class TaskInternalBase;
|
||||||
|
friend class TaskManager;
|
||||||
/// @endcond
|
/// @endcond
|
||||||
|
|
||||||
// Task Internal Storage
|
// Task Internal Storage
|
||||||
|
@ -136,6 +136,19 @@ public:
|
|||||||
m_tasks.push_back(std::move(in_task));
|
m_tasks.push_back(std::move(in_task));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Task<> ReleaseManagedTask(const WeakTaskHandle& in_task)
|
||||||
|
{
|
||||||
|
auto itWeak = std::find(m_tasks.begin(), m_tasks.end(), in_task);
|
||||||
|
assert(itWeak != m_tasks.end());
|
||||||
|
m_tasks.erase(itWeak);
|
||||||
|
|
||||||
|
auto itStrong = std::find(m_strongRefs.begin(), m_strongRefs.end(), in_task);
|
||||||
|
assert(itStrong != m_strongRefs.end());
|
||||||
|
Task<> handle = itStrong->MoveToTask<void, eTaskRef::Strong, eTaskResumable::Yes>();
|
||||||
|
m_strongRefs.erase(itStrong);
|
||||||
|
return handle;
|
||||||
|
}
|
||||||
|
|
||||||
/// Call Task::Kill() on all tasks (managed + unmanaged)
|
/// Call Task::Kill() on all tasks (managed + unmanaged)
|
||||||
void KillAllTasks()
|
void KillAllTasks()
|
||||||
{
|
{
|
||||||
@ -174,6 +187,7 @@ public:
|
|||||||
size_t writeIdx = 0;
|
size_t writeIdx = 0;
|
||||||
for(size_t readIdx = 0; readIdx < m_tasks.size(); ++readIdx)
|
for(size_t readIdx = 0; readIdx < m_tasks.size(); ++readIdx)
|
||||||
{
|
{
|
||||||
|
m_currentTask = m_tasks[readIdx];
|
||||||
if(m_tasks[readIdx].Resume() != eTaskStatus::Done)
|
if(m_tasks[readIdx].Resume() != eTaskStatus::Done)
|
||||||
{
|
{
|
||||||
if(writeIdx != readIdx)
|
if(writeIdx != readIdx)
|
||||||
@ -184,6 +198,7 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_tasks.resize(writeIdx);
|
m_tasks.resize(writeIdx);
|
||||||
|
m_currentTask = {};
|
||||||
|
|
||||||
// Prune strong tasks that are done
|
// Prune strong tasks that are done
|
||||||
auto removeIt = m_strongRefs.erase(std::remove_if(m_strongRefs.begin(), m_strongRefs.end(), [](const auto& in_taskHandle) {
|
auto removeIt = m_strongRefs.erase(std::remove_if(m_strongRefs.begin(), m_strongRefs.end(), [](const auto& in_taskHandle) {
|
||||||
@ -191,6 +206,11 @@ public:
|
|||||||
}), m_strongRefs.end());
|
}), m_strongRefs.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
WeakTaskHandle GetCurrentTask()
|
||||||
|
{
|
||||||
|
return m_currentTask;
|
||||||
|
}
|
||||||
|
|
||||||
/// Get a debug string containing a list of all active tasks
|
/// Get a debug string containing a list of all active tasks
|
||||||
std::string GetDebugString(std::optional<TaskDebugStackFormatter> in_formatter = {}) const
|
std::string GetDebugString(std::optional<TaskDebugStackFormatter> in_formatter = {}) const
|
||||||
{
|
{
|
||||||
@ -212,6 +232,7 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::vector<WeakTask> m_tasks;
|
std::vector<WeakTask> m_tasks;
|
||||||
std::vector<TaskHandle<>> m_strongRefs;
|
std::vector<TaskHandle<>> m_strongRefs;
|
||||||
|
WeakTaskHandle m_currentTask;
|
||||||
};
|
};
|
||||||
|
|
||||||
NAMESPACE_SQUID_END
|
NAMESPACE_SQUID_END
|
||||||
|
Loading…
x
Reference in New Issue
Block a user