Android: Add runOnAndroidThreadSync
This is a convenient function which waits (timoutMS) for the runnable to be executed. Change-Id: I2c0f262d3795c29961e8182b7ffc35a2c6f8a1f6 Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
This commit is contained in:
parent
7696ff89c9
commit
4bf741066d
@ -41,6 +41,7 @@
|
||||
#include "qmutex.h"
|
||||
#include "qlist.h"
|
||||
#include "qsemaphore.h"
|
||||
#include "qsharedpointer.h"
|
||||
#include "qvector.h"
|
||||
#include <QtCore/qrunnable.h>
|
||||
|
||||
@ -338,6 +339,16 @@ void QtAndroidPrivate::runOnAndroidThread(const QtAndroidPrivate::Runnable &runn
|
||||
env->CallStaticVoidMethod(g_jNativeClass, g_runPendingCppRunnablesMethodID);
|
||||
}
|
||||
|
||||
void QtAndroidPrivate::runOnAndroidThreadSync(const QtAndroidPrivate::Runnable &runnable, JNIEnv *env, int timeoutMs)
|
||||
{
|
||||
QSharedPointer<QSemaphore> sem(new QSemaphore);
|
||||
runOnAndroidThread([&runnable, sem]{
|
||||
runnable();
|
||||
sem->release();
|
||||
}, env);
|
||||
sem->tryAcquire(1, timeoutMs);
|
||||
}
|
||||
|
||||
void QtAndroidPrivate::registerGenericMotionEventListener(QtAndroidPrivate::GenericMotionEventListener *listener)
|
||||
{
|
||||
QMutexLocker locker(&g_genericMotionEventListeners()->mutex);
|
||||
|
@ -105,6 +105,7 @@ namespace QtAndroidPrivate
|
||||
jobject classLoader();
|
||||
Q_CORE_EXPORT jint androidSdkVersion();
|
||||
Q_CORE_EXPORT void runOnAndroidThread(const Runnable &runnable, JNIEnv *env);
|
||||
Q_CORE_EXPORT void runOnAndroidThreadSync(const Runnable &runnable, JNIEnv *env, int timeoutMs = INT_MAX);
|
||||
Q_CORE_EXPORT void runOnUiThread(QRunnable *runnable, JNIEnv *env);
|
||||
|
||||
Q_CORE_EXPORT void handleActivityResult(jint requestCode, jint resultCode, jobject data);
|
||||
|
Loading…
Reference in New Issue
Block a user