From be1c0721577dd07d696b6647d877160b7d9d8188 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Sun, 12 Nov 2023 14:10:45 +0100 Subject: [PATCH] TaskTree: Delete runtime data earlier Delete the runtime node just after the task / container is finished, instead of when all other tasks in parent container are finished. Change-Id: I5fa3bc92324e8274b023fbc20e4bbede9824f47a Reviewed-by: Qt CI Bot Reviewed-by: hjk --- src/libs/solutions/tasking/tasktree.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/libs/solutions/tasking/tasktree.cpp b/src/libs/solutions/tasking/tasktree.cpp index fd13268c2df..2b361441dec 100644 --- a/src/libs/solutions/tasking/tasktree.cpp +++ b/src/libs/solutions/tasking/tasktree.cpp @@ -1234,6 +1234,7 @@ public: bool isStarting() const { return m_startGuard.isLocked(); } bool updateSuccessBit(bool success); int currentLimit() const; + void deleteChild(TaskRuntimeNode *node); const TaskContainer &m_taskContainer; // Not owning. TaskRuntimeNode *m_parentNode = nullptr; // Not owning. @@ -1394,6 +1395,14 @@ int TaskRuntimeContainer::currentLimit() const ? qMin(m_doneCount + m_taskContainer.m_parallelLimit, childCount) : childCount; } +void TaskRuntimeContainer::deleteChild(TaskRuntimeNode *node) +{ + const int index = m_children.indexOf(node); + QT_CHECK(index >= 0); + m_children[index] = nullptr; + delete node; +} + SetupResult TaskTreePrivate::start(TaskRuntimeContainer *container) { SetupResult startAction = SetupResult::Continue; @@ -1422,11 +1431,15 @@ SetupResult TaskTreePrivate::continueStart(TaskRuntimeContainer *container, Setu if (groupAction != SetupResult::Continue) { const bool bit = container->updateSuccessBit(groupAction == SetupResult::StopWithSuccess); TaskRuntimeContainer *parentContainer = container->m_parentContainer; + TaskRuntimeNode *parentNode = container->m_parentNode; + QT_CHECK(parentNode); const bool result = invokeDoneHandler(container, bit ? DoneWith::Success : DoneWith::Error); if (parentContainer) { + parentContainer->deleteChild(parentNode); if (!parentContainer->isStarting()) childDone(parentContainer, result); } else { + QT_CHECK(m_runtimeRoot.get() == parentNode); m_runtimeRoot.reset(); emitDone(result ? DoneWith::Success : DoneWith::Error); } @@ -1547,11 +1560,13 @@ SetupResult TaskTreePrivate::start(TaskRuntimeNode *node) q, [this, node, unwindAction](bool success) { const bool result = invokeDoneHandler(node, success ? DoneWith::Success : DoneWith::Error); QObject::disconnect(node->m_task.get(), &TaskInterface::done, q, nullptr); - node->m_task.release()->deleteLater(); // TODO: delete later this??? - if (node->m_parentContainer->isStarting()) + node->m_task.release()->deleteLater(); + TaskRuntimeContainer *parentContainer = node->m_parentContainer; + parentContainer->deleteChild(node); + if (parentContainer->isStarting()) *unwindAction = toSetupResult(result); else - childDone(node->m_parentContainer, result); + childDone(parentContainer, result); }); node->m_task->start();