From faf6ae04c2438f4a3f8c36a3c6f803aee1da3ef8 Mon Sep 17 00:00:00 2001 From: Jarek Kobus Date: Mon, 10 Jun 2024 11:59:09 +0200 Subject: [PATCH] TaskTree: Qt-ify the code (part 3) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 11. Replace local lambda with static method, otherwise getting: "qarraydatapointer.h:110:17: error: pointer may be used after ‘void free(void*)’" on rhel-9.2-gcc12. 12. Use std::optional::reset() instead of "= {}", otherwise getting: "error: use of overloaded operator '=' is ambiguous (with operand types 'std::optional' and 'void')" on vxworks-imx6. Amends 88ee3aa90840e9c4fa13e79a29bbe9dba50d782b Amends 6621c68ca970c6760fbf10deae0a175202c6a8e1 Change-Id: Ie1631e119cb89d23a6acb3b4c39199e6ebaf1ea1 Reviewed-by: hjk --- src/libs/solutions/tasking/barrier.cpp | 2 +- src/libs/solutions/tasking/tasktree.cpp | 21 ++++++++++++--------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/libs/solutions/tasking/barrier.cpp b/src/libs/solutions/tasking/barrier.cpp index 650aae3403b..126d4f3b8a5 100644 --- a/src/libs/solutions/tasking/barrier.cpp +++ b/src/libs/solutions/tasking/barrier.cpp @@ -24,7 +24,7 @@ void Barrier::start() { QT_ASSERT(!isRunning(), return); m_current = 0; - m_result = {}; + m_result.reset(); } void Barrier::advance() diff --git a/src/libs/solutions/tasking/tasktree.cpp b/src/libs/solutions/tasking/tasktree.cpp index 2c7a5a8dedb..d923eb31d0e 100644 --- a/src/libs/solutions/tasking/tasktree.cpp +++ b/src/libs/solutions/tasking/tasktree.cpp @@ -1450,6 +1450,11 @@ ExecutableItem ExecutableItem::withTimeout(milliseconds timeout, static QString currentTime() { return QTime::currentTime().toString(Qt::ISODateWithMs); } +static QString logHeader(const QString &logName) +{ + return QString::fromLatin1("TASK TREE LOG [%1] \"%2\"").arg(currentTime(), logName); +}; + /*! Attaches a custom debug printout to a copy of \c this ExecutableItem, issued on task startup and after the task is finished, and returns the coupled item. @@ -1463,9 +1468,6 @@ static QString currentTime() { return QTime::currentTime().toString(Qt::ISODateW */ ExecutableItem ExecutableItem::withLog(const QString &logName) const { - const auto header = [logName] { - return QString::fromLatin1("TASK TREE LOG [%1] \"%2\"").arg(currentTime(), logName); - }; struct LogStorage { time_point start; @@ -1474,21 +1476,22 @@ ExecutableItem ExecutableItem::withLog(const QString &logName) const const Storage storage; return Group { storage, - onGroupSetup([storage, header] { + onGroupSetup([storage, logName] { storage->start = system_clock::now(); storage->asyncCount = activeTaskTree()->asyncCount(); - qDebug().noquote() << header() << "started."; + qDebug().noquote().nospace() << logHeader(logName) << " started."; }), *this, - onGroupDone([storage, header](DoneWith result) { + onGroupDone([storage, logName](DoneWith result) { const auto elapsed = duration_cast(system_clock::now() - storage->start); const int asyncCountDiff = activeTaskTree()->asyncCount() - storage->asyncCount; QT_CHECK(asyncCountDiff >= 0); const QMetaEnum doneWithEnum = QMetaEnum::fromType(); const QString syncType = asyncCountDiff ? QString::fromLatin1("asynchronously") : QString::fromLatin1("synchronously"); - qDebug().noquote().nospace() << header() << " finished " << syncType << " with " - << doneWithEnum.valueToKey(int(result)) << " within " << elapsed.count() << "ms."; + qDebug().noquote().nospace() << logHeader(logName) << " finished " << syncType + << " with " << doneWithEnum.valueToKey(int(result)) + << " within " << elapsed.count() << "ms."; }) }; } @@ -3383,7 +3386,7 @@ TimeoutTaskAdapter::~TimeoutTaskAdapter() void TimeoutTaskAdapter::start() { m_timerId = scheduleTimeout(*task(), this, [this] { - m_timerId = {}; + m_timerId.reset(); emit done(DoneResult::Success); }); }