From a028d463508ed0612f7fd1d2b1365c5c091dc1b4 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Tue, 23 Apr 2013 11:49:36 +0200 Subject: [PATCH] Debugger: fix race condition in block mode 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 --- src/qml/debugger/qqmldebugserver.cpp | 15 ++++++--------- 1 files changed, 6 insertions(+), 9 deletions(-) diff --git a/src/qml/debugger/qqmldebugserver.cpp b/src/qml/debugger/qqmldebugserver.cpp index e263343..dcb5539 100644 --- a/src/qml/debugger/qqmldebugserver.cpp +++ b/src/qml/debugger/qqmldebugserver.cpp @@ -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."); -- 1.7.2.5