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:
parent
c020e5fef7
commit
a3d8512fe1
@ -159,8 +159,8 @@ QFuture<QVariant> QNativeInterface::QAndroidApplication::runOnAndroidMainThread(
|
|||||||
QFuture<QVariant> future = promise->future();
|
QFuture<QVariant> future = promise->future();
|
||||||
promise->start();
|
promise->start();
|
||||||
|
|
||||||
(void) QtConcurrent::run([=, &future]() {
|
|
||||||
if (!timeout.isForever()) {
|
if (!timeout.isForever()) {
|
||||||
|
(void) QtConcurrent::run([=, &future]() {
|
||||||
QEventLoop loop;
|
QEventLoop loop;
|
||||||
QTimer::singleShot(timeout.remainingTime(), &loop, [&]() {
|
QTimer::singleShot(timeout.remainingTime(), &loop, [&]() {
|
||||||
future.cancel();
|
future.cancel();
|
||||||
@ -177,8 +177,8 @@ QFuture<QVariant> QNativeInterface::QAndroidApplication::runOnAndroidMainThread(
|
|||||||
});
|
});
|
||||||
watcher.setFuture(future);
|
watcher.setFuture(future);
|
||||||
loop.exec();
|
loop.exec();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
QMutexLocker locker(&g_pendingRunnablesMutex);
|
QMutexLocker locker(&g_pendingRunnablesMutex);
|
||||||
g_pendingRunnables->push_back(std::pair(runnable, promise));
|
g_pendingRunnables->push_back(std::pair(runnable, promise));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user