Fix async tasks destruction to wait on the dependencies in chain
This commit is contained in:
@@ -226,6 +226,27 @@ void Task::OnEnd()
|
||||
{
|
||||
ASSERT(!IsRunning());
|
||||
|
||||
// Add to delete
|
||||
DeleteObject(30.0f, false);
|
||||
if (_continueWith && !_continueWith->IsEnded())
|
||||
{
|
||||
// Let next task do the cleanup (to ensure whole tasks chain shares the lifetime)
|
||||
_continueWith->_rootForRemoval = _rootForRemoval ? _rootForRemoval : this;
|
||||
}
|
||||
else
|
||||
{
|
||||
constexpr float timeToLive = 30.0f;
|
||||
|
||||
// Remove task chain starting from the root
|
||||
if (_rootForRemoval)
|
||||
{
|
||||
auto task = _rootForRemoval;
|
||||
while (task != this)
|
||||
{
|
||||
task->DeleteObject(timeToLive, false);
|
||||
task = task->_continueWith;
|
||||
}
|
||||
}
|
||||
|
||||
// Add to delete
|
||||
DeleteObject(timeToLive, false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,11 @@ protected:
|
||||
/// </summary>
|
||||
Task* _continueWith = nullptr;
|
||||
|
||||
/// <summary>
|
||||
/// The task that's starts removal chain, used to sync whole task chain lifetime.
|
||||
/// </summary>
|
||||
Task* _rootForRemoval = nullptr;
|
||||
|
||||
void SetState(TaskState state)
|
||||
{
|
||||
Platform::AtomicStore((int64 volatile*)&_state, (uint64)state);
|
||||
|
||||
Reference in New Issue
Block a user