Fix potential deadlook in threaded renderloop.
authorGunnar Sletta <gunnar.sletta@jollamobile.com>
Thu, 14 Aug 2014 06:38:12 +0000 (06:38 +0000)
committerGunnar Sletta <gunnar.sletta@jollamobile.com>
Thu, 14 Aug 2014 09:20:20 +0000 (11:20 +0200)
Change-Id: I415e632aa4e584c8fca745581f25a676db0eae42
Reviewed-by: Giulio Camuffo <giulio.camuffo@jollamobile.com>
Reviewed-by: Robin Burchell <robin.burchell@viroteck.net>
src/quick/scenegraph/qsgthreadedrenderloop.cpp

index 296050e..c17eb91 100644 (file)
@@ -1116,6 +1116,18 @@ void QSGThreadedRenderLoop::releaseResources(QQuickWindow *window, bool inDestru
         w->thread->waitCondition.wait(&w->thread->mutex);
 
         delete fallback;
+
+        // Avoid a shutdown race condition.
+        // If SG is invalidated and 'active' becomes false, the thread's run()
+        // method will exit. handleExposure() relies on QThread::isRunning() (because it
+        // potentially needs to start the thread again) and our mutex cannot be used to
+        // track the thread stopping, so we wait a few nanoseconds extra so the thread
+        // can exit properly.
+        if (!w->thread->active) {
+            QSG_GUI_DEBUG(w->window, " - waiting for render thread to exit");
+            w->thread->wait();
+            QSG_GUI_DEBUG(w->window, " - render thread finished");
+        }
     }
     w->thread->mutex.unlock();
 }