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 <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2023-11-12 14:10:45 +01:00
parent 3ae0185817
commit be1c072157

View File

@@ -1234,6 +1234,7 @@ public:
bool isStarting() const { return m_startGuard.isLocked(); } bool isStarting() const { return m_startGuard.isLocked(); }
bool updateSuccessBit(bool success); bool updateSuccessBit(bool success);
int currentLimit() const; int currentLimit() const;
void deleteChild(TaskRuntimeNode *node);
const TaskContainer &m_taskContainer; // Not owning. const TaskContainer &m_taskContainer; // Not owning.
TaskRuntimeNode *m_parentNode = nullptr; // 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; ? 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 TaskTreePrivate::start(TaskRuntimeContainer *container)
{ {
SetupResult startAction = SetupResult::Continue; SetupResult startAction = SetupResult::Continue;
@@ -1422,11 +1431,15 @@ SetupResult TaskTreePrivate::continueStart(TaskRuntimeContainer *container, Setu
if (groupAction != SetupResult::Continue) { if (groupAction != SetupResult::Continue) {
const bool bit = container->updateSuccessBit(groupAction == SetupResult::StopWithSuccess); const bool bit = container->updateSuccessBit(groupAction == SetupResult::StopWithSuccess);
TaskRuntimeContainer *parentContainer = container->m_parentContainer; TaskRuntimeContainer *parentContainer = container->m_parentContainer;
TaskRuntimeNode *parentNode = container->m_parentNode;
QT_CHECK(parentNode);
const bool result = invokeDoneHandler(container, bit ? DoneWith::Success : DoneWith::Error); const bool result = invokeDoneHandler(container, bit ? DoneWith::Success : DoneWith::Error);
if (parentContainer) { if (parentContainer) {
parentContainer->deleteChild(parentNode);
if (!parentContainer->isStarting()) if (!parentContainer->isStarting())
childDone(parentContainer, result); childDone(parentContainer, result);
} else { } else {
QT_CHECK(m_runtimeRoot.get() == parentNode);
m_runtimeRoot.reset(); m_runtimeRoot.reset();
emitDone(result ? DoneWith::Success : DoneWith::Error); emitDone(result ? DoneWith::Success : DoneWith::Error);
} }
@@ -1547,11 +1560,13 @@ SetupResult TaskTreePrivate::start(TaskRuntimeNode *node)
q, [this, node, unwindAction](bool success) { q, [this, node, unwindAction](bool success) {
const bool result = invokeDoneHandler(node, success ? DoneWith::Success : DoneWith::Error); const bool result = invokeDoneHandler(node, success ? DoneWith::Success : DoneWith::Error);
QObject::disconnect(node->m_task.get(), &TaskInterface::done, q, nullptr); QObject::disconnect(node->m_task.get(), &TaskInterface::done, q, nullptr);
node->m_task.release()->deleteLater(); // TODO: delete later this??? node->m_task.release()->deleteLater();
if (node->m_parentContainer->isStarting()) TaskRuntimeContainer *parentContainer = node->m_parentContainer;
parentContainer->deleteChild(node);
if (parentContainer->isStarting())
*unwindAction = toSetupResult(result); *unwindAction = toSetupResult(result);
else else
childDone(node->m_parentContainer, result); childDone(parentContainer, result);
}); });
node->m_task->start(); node->m_task->start();