summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel
diff options
context:
space:
mode:
authorBogDan Vatra <bogdan@kdab.com>2016-01-27 10:29:32 +0200
committerBogDan Vatra <bogdan@kdab.com>2016-02-04 17:53:40 +0000
commit4bf741066dff72190725b9aad9d1f2c1d0316ef9 (patch)
treeb9b4979a010a721075ef7b4af532bcd354da44d2 /src/corelib/kernel
parent7696ff89c9a9cc8f738e3134bfcab831ff314968 (diff)
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>
Diffstat (limited to 'src/corelib/kernel')
-rw-r--r--src/corelib/kernel/qjnihelpers.cpp11
-rw-r--r--src/corelib/kernel/qjnihelpers_p.h1
2 files changed, 12 insertions, 0 deletions
diff --git a/src/corelib/kernel/qjnihelpers.cpp b/src/corelib/kernel/qjnihelpers.cpp
index f5e4aceff3..2324a615d5 100644
--- a/src/corelib/kernel/qjnihelpers.cpp
+++ b/src/corelib/kernel/qjnihelpers.cpp
@@ -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);
diff --git a/src/corelib/kernel/qjnihelpers_p.h b/src/corelib/kernel/qjnihelpers_p.h
index 3f24597312..1bffd26e08 100644
--- a/src/corelib/kernel/qjnihelpers_p.h
+++ b/src/corelib/kernel/qjnihelpers_p.h
@@ -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);