QAndroidNaticeInterface: replace a pair with a struct
Nicer member names make the code using the type more readable. It also allows to add other members later. Pick-to: 6.5 6.4 6.2 Change-Id: I69f1f97673a8f1ad8eb73e4f1e5323eccf929413 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
parent
500e161987
commit
b6fdf34dfc
@ -19,8 +19,12 @@ QT_BEGIN_NAMESPACE
|
|||||||
#if QT_CONFIG(future) && !defined(QT_NO_QOBJECT)
|
#if QT_CONFIG(future) && !defined(QT_NO_QOBJECT)
|
||||||
static const char qtNativeClassName[] = "org/qtproject/qt/android/QtNative";
|
static const char qtNativeClassName[] = "org/qtproject/qt/android/QtNative";
|
||||||
|
|
||||||
typedef std::pair<std::function<QVariant()>, QSharedPointer<QPromise<QVariant>>> RunnablePair;
|
struct PendingRunnable {
|
||||||
typedef std::deque<RunnablePair> PendingRunnables;
|
std::function<QVariant()> function;
|
||||||
|
QSharedPointer<QPromise<QVariant>> promise;
|
||||||
|
};
|
||||||
|
|
||||||
|
using PendingRunnables = std::deque<PendingRunnable>;
|
||||||
Q_GLOBAL_STATIC(PendingRunnables, g_pendingRunnables);
|
Q_GLOBAL_STATIC(PendingRunnables, g_pendingRunnables);
|
||||||
Q_CONSTINIT static QBasicMutex g_pendingRunnablesMutex;
|
Q_CONSTINIT static QBasicMutex g_pendingRunnablesMutex;
|
||||||
#endif
|
#endif
|
||||||
@ -191,7 +195,11 @@ QFuture<QVariant> QNativeInterface::QAndroidApplication::runOnAndroidMainThread(
|
|||||||
}
|
}
|
||||||
|
|
||||||
QMutexLocker locker(&g_pendingRunnablesMutex);
|
QMutexLocker locker(&g_pendingRunnablesMutex);
|
||||||
g_pendingRunnables->push_back(std::pair(runnable, promise));
|
#ifdef __cpp_aggregate_paren_init
|
||||||
|
g_pendingRunnables->emplace_back(runnable, std::move(promise));
|
||||||
|
#else
|
||||||
|
g_pendingRunnables->push_back({runnable, std::move(promise)});
|
||||||
|
#endif
|
||||||
locker.unlock();
|
locker.unlock();
|
||||||
|
|
||||||
QJniObject::callStaticMethod<void>(qtNativeClassName,
|
QJniObject::callStaticMethod<void>(qtNativeClassName,
|
||||||
@ -209,15 +217,14 @@ static void runPendingCppRunnables(JNIEnv */*env*/, jobject /*obj*/)
|
|||||||
if (g_pendingRunnables->empty())
|
if (g_pendingRunnables->empty())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
std::pair pair = std::move(g_pendingRunnables->front());
|
PendingRunnable r = std::move(g_pendingRunnables->front());
|
||||||
g_pendingRunnables->pop_front();
|
g_pendingRunnables->pop_front();
|
||||||
locker.unlock();
|
locker.unlock();
|
||||||
|
|
||||||
// run the runnable outside the sync block!
|
// run the runnable outside the sync block!
|
||||||
auto promise = pair.second;
|
if (!r.promise->isCanceled())
|
||||||
if (!promise->isCanceled())
|
r.promise->addResult(r.function());
|
||||||
promise->addResult(pair.first());
|
r.promise->finish();
|
||||||
promise->finish();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user