Don't create a QRunnable in QAndroidApplication::runOnAndroidMainThread() w/o timeout

Creating a QRunnable is expensive business, incl. setting up
QThreadPool::globalInstance() if it wasn't set up already, so don't do
it for a no-op task.

Somewhat mitigates, but doesn't fix, QTBUG-109586.

Task-number: QTBUG-109586
Change-Id: If2043134414d68adc9188e5bb7650ca08046b4aa
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
(cherry picked from commit 26ea6157e6429a6ba0794272df195c0bc591cda9)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2022-12-22 11:36:04 +01:00 committed by Qt Cherry-pick Bot
parent c020e5fef7
commit a3d8512fe1

View File

@ -159,8 +159,8 @@ QFuture<QVariant> QNativeInterface::QAndroidApplication::runOnAndroidMainThread(
QFuture<QVariant> future = promise->future();
promise->start();
(void) QtConcurrent::run([=, &future]() {
if (!timeout.isForever()) {
if (!timeout.isForever()) {
(void) QtConcurrent::run([=, &future]() {
QEventLoop loop;
QTimer::singleShot(timeout.remainingTime(), &loop, [&]() {
future.cancel();
@ -177,8 +177,8 @@ QFuture<QVariant> QNativeInterface::QAndroidApplication::runOnAndroidMainThread(
});
watcher.setFuture(future);
loop.exec();
}
});
});
}
QMutexLocker locker(&g_pendingRunnablesMutex);
g_pendingRunnables->push_back(std::pair(runnable, promise));