TaskTree: Qt-ify the code (part 3)

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 88ee3aa908
Amends 6621c68ca9

Change-Id: Ie1631e119cb89d23a6acb3b4c39199e6ebaf1ea1
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2024-06-10 11:59:09 +02:00
parent dbe2e422f7
commit faf6ae04c2
2 changed files with 13 additions and 10 deletions

View File

@@ -24,7 +24,7 @@ void Barrier::start()
{ {
QT_ASSERT(!isRunning(), return); QT_ASSERT(!isRunning(), return);
m_current = 0; m_current = 0;
m_result = {}; m_result.reset();
} }
void Barrier::advance() void Barrier::advance()

View File

@@ -1450,6 +1450,11 @@ ExecutableItem ExecutableItem::withTimeout(milliseconds timeout,
static QString currentTime() { return QTime::currentTime().toString(Qt::ISODateWithMs); } 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, 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. 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 ExecutableItem ExecutableItem::withLog(const QString &logName) const
{ {
const auto header = [logName] {
return QString::fromLatin1("TASK TREE LOG [%1] \"%2\"").arg(currentTime(), logName);
};
struct LogStorage struct LogStorage
{ {
time_point<system_clock, nanoseconds> start; time_point<system_clock, nanoseconds> start;
@@ -1474,21 +1476,22 @@ ExecutableItem ExecutableItem::withLog(const QString &logName) const
const Storage<LogStorage> storage; const Storage<LogStorage> storage;
return Group { return Group {
storage, storage,
onGroupSetup([storage, header] { onGroupSetup([storage, logName] {
storage->start = system_clock::now(); storage->start = system_clock::now();
storage->asyncCount = activeTaskTree()->asyncCount(); storage->asyncCount = activeTaskTree()->asyncCount();
qDebug().noquote() << header() << "started."; qDebug().noquote().nospace() << logHeader(logName) << " started.";
}), }),
*this, *this,
onGroupDone([storage, header](DoneWith result) { onGroupDone([storage, logName](DoneWith result) {
const auto elapsed = duration_cast<milliseconds>(system_clock::now() - storage->start); const auto elapsed = duration_cast<milliseconds>(system_clock::now() - storage->start);
const int asyncCountDiff = activeTaskTree()->asyncCount() - storage->asyncCount; const int asyncCountDiff = activeTaskTree()->asyncCount() - storage->asyncCount;
QT_CHECK(asyncCountDiff >= 0); QT_CHECK(asyncCountDiff >= 0);
const QMetaEnum doneWithEnum = QMetaEnum::fromType<DoneWith>(); const QMetaEnum doneWithEnum = QMetaEnum::fromType<DoneWith>();
const QString syncType = asyncCountDiff ? QString::fromLatin1("asynchronously") const QString syncType = asyncCountDiff ? QString::fromLatin1("asynchronously")
: QString::fromLatin1("synchronously"); : QString::fromLatin1("synchronously");
qDebug().noquote().nospace() << header() << " finished " << syncType << " with " qDebug().noquote().nospace() << logHeader(logName) << " finished " << syncType
<< doneWithEnum.valueToKey(int(result)) << " within " << elapsed.count() << "ms."; << " with " << doneWithEnum.valueToKey(int(result))
<< " within " << elapsed.count() << "ms.";
}) })
}; };
} }
@@ -3383,7 +3386,7 @@ TimeoutTaskAdapter::~TimeoutTaskAdapter()
void TimeoutTaskAdapter::start() void TimeoutTaskAdapter::start()
{ {
m_timerId = scheduleTimeout(*task(), this, [this] { m_timerId = scheduleTimeout(*task(), this, [this] {
m_timerId = {}; m_timerId.reset();
emit done(DoneResult::Success); emit done(DoneResult::Success);
}); });
} }