Android: Use QMutexLock in camera callbacks.
authorChristian Strømme <christian.stromme@digia.com>
Thu, 3 Apr 2014 15:26:05 +0000 (17:26 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 15 Apr 2014 14:46:49 +0000 (16:46 +0200)
We should not release the locks before the native callbacks returns.

Change-Id: Ia2691f6c5be66a3dcf371e48e3bac7498b401833
Reviewed-by: Yoann Lopes <yoann.lopes@digia.com>
src/plugins/android/src/wrappers/jcamera.cpp

index b0e9f89..f43e230 100644 (file)
@@ -82,27 +82,24 @@ static QJNIObjectPrivate rectToArea(const QRect &rect)
 // native method for QtCamera.java
 static void notifyAutoFocusComplete(JNIEnv* , jobject, int id, jboolean success)
 {
-    g_objectMapMutex.lock();
+    QMutexLocker locker(&g_objectMapMutex);
     JCamera *obj = g_objectMap.value(id, 0);
-    g_objectMapMutex.unlock();
     if (obj)
         Q_EMIT obj->autoFocusComplete(success);
 }
 
 static void notifyPictureExposed(JNIEnv* , jobject, int id)
 {
-    g_objectMapMutex.lock();
+    QMutexLocker locker(&g_objectMapMutex);
     JCamera *obj = g_objectMap.value(id, 0);
-    g_objectMapMutex.unlock();
     if (obj)
         Q_EMIT obj->pictureExposed();
 }
 
 static void notifyPictureCaptured(JNIEnv *env, jobject, int id, jbyteArray data)
 {
-    g_objectMapMutex.lock();
+    QMutexLocker locker(&g_objectMapMutex);
     JCamera *obj = g_objectMap.value(id, 0);
-    g_objectMapMutex.unlock();
     if (obj) {
         QByteArray bytes;
         int arrayLength = env->GetArrayLength(data);
@@ -114,9 +111,8 @@ static void notifyPictureCaptured(JNIEnv *env, jobject, int id, jbyteArray data)
 
 static void notifyFrameFetched(JNIEnv *env, jobject, int id, jbyteArray data)
 {
-    g_objectMapMutex.lock();
+    QMutexLocker locker(&g_objectMapMutex);
     JCamera *obj = g_objectMap.value(id, 0);
-    g_objectMapMutex.unlock();
     if (obj) {
         QByteArray bytes;
         int arrayLength = env->GetArrayLength(data);