Debugger: fix race condition in block mode
authorKai Koehne <kai.koehne@digia.com>
Tue, 23 Apr 2013 09:49:36 +0000 (11:49 +0200)
committerThe Qt Project <gerrit-noreply@qt-project.org>
Tue, 23 Apr 2013 13:40:31 +0000 (15:40 +0200)
Make sure that the GUI thread & debugger thread actually sync on startup. So far
the GUI thread would block forever in waitCondition.wait() if the debugger thread
spawns & receives the HELLO before.

Also remove unused code and rename variables to make their use more obvious.

Change-Id: I8285e8860667496d491807e696535353d9f14dea
Reviewed-by: Aurindam Jana <aurindam.jana@digia.com>
src/qml/debugger/qqmldebugserver.cpp

index e263343..dcb5539 100644 (file)
@@ -102,9 +102,8 @@ public:
     bool gotHello;
     bool blockingMode;
 
-    QMutex messageArrivedMutex;
-    QWaitCondition messageArrivedCondition;
-    QStringList waitingForMessageNames;
+    QMutex helloMutex;
+    QWaitCondition helloCondition;
     QQmlDebugServerThread *thread;
     QPluginLoader loader;
     QAtomicInt changeServiceStateCalls;
@@ -331,11 +330,11 @@ QQmlDebugServer *QQmlDebugServer::instance()
                 QQmlDebugServerPrivate *d = qQmlDebugServer->d_func();
                 d->blockingMode = block;
 
-                QMutexLocker locker(&d->messageArrivedMutex);
+                QMutexLocker locker(&d->helloMutex);
                 thread->start();
 
                 if (d->blockingMode)
-                    d->messageArrivedCondition.wait(&d->messageArrivedMutex);
+                    d->helloCondition.wait(&d->helloMutex);
 
             } else {
                 qWarning() << QString(QLatin1String(
@@ -447,7 +446,8 @@ void QQmlDebugServer::receiveMessage(const QByteArray &message)
                 d->_q_changeServiceState(iter.value()->name(), newState);
             }
 
-            d->messageArrivedCondition.wakeAll();
+            QMutexLocker helloLock(&d->helloMutex);
+            d->helloCondition.wakeAll();
 
         } else if (op == 1) {
 
@@ -487,9 +487,6 @@ void QQmlDebugServer::receiveMessage(const QByteArray &message)
                 qWarning() << "QML Debugger: Message received for missing plugin" << name << '.';
             } else {
                 (*iter)->messageReceived(message);
-
-                if (d->waitingForMessageNames.removeOne(name))
-                    d->messageArrivedCondition.wakeAll();
             }
         } else {
             qWarning("QML Debugger: Invalid hello message.");