Don't hang the worker script engine
authorCharles Yin <charles.yin@nokia.com>
Wed, 18 Jan 2012 01:22:31 +0000 (11:22 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 24 Jan 2012 09:53:44 +0000 (10:53 +0100)
1. Wake up the syncDone wait condition when delete the QDeclarativeListModelWorkerAgent,
otherwise the the whole worker script engine thread will hang at the sync() call
and can't exit gracefully.
2. Call QCoreApplication::processEvents() before delete the worker script engine to
cleanup all pending events in main thread to release wait conditions which
some worker scripts/agents are waiting for (QDeclarativeListModelWorkerAgent::sync() for example)

Change-Id: Ia3712318771633e68238b4d629ba870ff7ce45b9
Reviewed-by: Yunqiao Yin <charles.yin@nokia.com>
src/declarative/qml/qdeclarativelistmodelworkeragent.cpp
src/declarative/qml/qdeclarativelistmodelworkeragent_p.h
src/declarative/qml/qdeclarativeworkerscript.cpp

index 1848cf0..91c0a6c 100644 (file)
@@ -92,6 +92,13 @@ QDeclarativeListModelWorkerAgent::QDeclarativeListModelWorkerAgent(QDeclarativeL
 {
 }
 
+QDeclarativeListModelWorkerAgent::~QDeclarativeListModelWorkerAgent()
+{
+    mutex.lock();
+    syncDone.wakeAll();
+    mutex.unlock();
+}
+
 void QDeclarativeListModelWorkerAgent::setV8Engine(QV8Engine *eng)
 {
     m_copy->m_engine = eng;
index 7263afb..6c97fc5 100644 (file)
@@ -75,7 +75,7 @@ class QDeclarativeListModelWorkerAgent : public QObject
 
 public:
     QDeclarativeListModelWorkerAgent(QDeclarativeListModel *);
-
+    ~QDeclarativeListModelWorkerAgent();
     void setV8Engine(QV8Engine *eng);
 
     void addref();
index ee325c1..bc7e645 100644 (file)
@@ -478,6 +478,10 @@ QDeclarativeWorkerScriptEngine::~QDeclarativeWorkerScriptEngine()
     QCoreApplication::postEvent(d, new QEvent((QEvent::Type)QDeclarativeWorkerScriptEnginePrivate::WorkerDestroyEvent));
     d->m_lock.unlock();
 
+    //We have to force to cleanup the main thread's event queue here
+    //to make sure the main GUI release all pending locks/wait conditions which
+    //some worker script/agent are waiting for (QDeclarativeListModelWorkerAgent::sync() for example).
+    QCoreApplication::processEvents();
     wait();
     d->deleteLater();
 }