aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/debugger/qqmldebugserver.cpp
diff options
context:
space:
mode:
authorKai Koehne <kai.koehne@nokia.com>2012-04-24 14:39:38 +0200
committerQt by Nokia <qt-info@nokia.com>2012-04-25 14:26:42 +0200
commit0d284ae2d62707e6c35c8d97ca73e974d35c4167 (patch)
treed41e0e0c64486a43c45db2c6a8ad3e1a9fba6ec9 /src/qml/debugger/qqmldebugserver.cpp
parente1583664fd8a9eb66e37bdd2e1476bbf90383a4c (diff)
Debugger: Fix race conditions in block mode
Using waitForMessage() in the constructor after registerService() is _not_ safe: You might get the first message already after the registerService() and before the waitForMessage() call. Instead, use QMutex/QWaitCondition to block the initialization. Also make the use of the block mode explicit, since the service might already be enabled also for non-blocking modes ... Change-Id: I387bfe0627c80e2029acff71f86d12cd9ab58de1 Reviewed-by: Kai Koehne <kai.koehne@nokia.com>
Diffstat (limited to 'src/qml/debugger/qqmldebugserver.cpp')
-rw-r--r--src/qml/debugger/qqmldebugserver.cpp33
1 files changed, 11 insertions, 22 deletions
diff --git a/src/qml/debugger/qqmldebugserver.cpp b/src/qml/debugger/qqmldebugserver.cpp
index d49d04f595..b247e43435 100644
--- a/src/qml/debugger/qqmldebugserver.cpp
+++ b/src/qml/debugger/qqmldebugserver.cpp
@@ -99,6 +99,7 @@ public:
mutable QReadWriteLock pluginsLock;
QStringList clientPlugins;
bool gotHello;
+ bool blockingMode;
QMutex messageArrivedMutex;
QWaitCondition messageArrivedCondition;
@@ -139,6 +140,7 @@ private:
QQmlDebugServerPrivate::QQmlDebugServerPrivate() :
connection(0),
gotHello(false),
+ blockingMode(false),
thread(0)
{
// used in _q_sendMessages
@@ -244,6 +246,12 @@ bool QQmlDebugServer::hasDebuggingClient() const
&& d->gotHello;
}
+bool QQmlDebugServer::blockingMode() const
+{
+ Q_D(const QQmlDebugServer);
+ return d->blockingMode;
+}
+
static QQmlDebugServer *qQmlDebugServer = 0;
@@ -305,10 +313,12 @@ QQmlDebugServer *QQmlDebugServer::instance()
thread->setPort(port, block, hostAddress);
QQmlDebugServerPrivate *d = qQmlDebugServer->d_func();
+ d->blockingMode = block;
+
QMutexLocker locker(&d->messageArrivedMutex);
thread->start();
- if (block)
+ if (d->blockingMode)
d->messageArrivedCondition.wait(&d->messageArrivedMutex);
} else {
@@ -576,27 +586,6 @@ void QQmlDebugServer::sendMessages(QQmlDebugService *service,
Q_ARG(QList<QByteArray>, prefixedMessages));
}
-bool QQmlDebugServer::waitForMessage(QQmlDebugService *service)
-{
- // to be executed in GUI thread
- Q_ASSERT(QThread::currentThread() == QCoreApplication::instance()->thread());
-
- Q_D(QQmlDebugServer);
- QReadLocker lock(&d->pluginsLock);
-
- if (!service
- || !d->plugins.contains(service->name()))
- return false;
-
- d->messageArrivedMutex.lock();
- d->waitingForMessageNames << service->name();
- do {
- d->messageArrivedCondition.wait(&d->messageArrivedMutex);
- } while (d->waitingForMessageNames.contains(service->name()));
- d->messageArrivedMutex.unlock();
- return true;
-}
-
QT_END_NAMESPACE
#include "moc_qqmldebugserver_p.cpp"