diff options
author | Kai Koehne <kai.koehne@nokia.com> | 2012-04-24 14:39:38 +0200 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-04-25 14:26:42 +0200 |
commit | 0d284ae2d62707e6c35c8d97ca73e974d35c4167 (patch) | |
tree | d41e0e0c64486a43c45db2c6a8ad3e1a9fba6ec9 /src/qml/debugger/qv8profilerservice.cpp | |
parent | e1583664fd8a9eb66e37bdd2e1476bbf90383a4c (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/qv8profilerservice.cpp')
-rw-r--r-- | src/qml/debugger/qv8profilerservice.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/qml/debugger/qv8profilerservice.cpp b/src/qml/debugger/qv8profilerservice.cpp index 1cd7606416..5cddea755c 100644 --- a/src/qml/debugger/qv8profilerservice.cpp +++ b/src/qml/debugger/qv8profilerservice.cpp @@ -45,6 +45,8 @@ #include <private/qv8profiler_p.h> #include <QtCore/QHash> +#include <QtCore/QMutex> +#include <QtCore/QWaitCondition> QT_BEGIN_NAMESPACE @@ -96,6 +98,8 @@ public: QList<QV8ProfilerData> m_data; bool initialized; + QMutex initializeMutex; + QWaitCondition initializeCondition; QList<QString> m_ongoing; }; @@ -104,10 +108,12 @@ QV8ProfilerService::QV8ProfilerService(QObject *parent) { Q_D(QV8ProfilerService); - if (registerService() == Enabled) { - // ,block mode, client attached - while (!d->initialized) - waitForMessage(); + QMutexLocker lock(&d->initializeMutex); + + if (registerService() == Enabled + && QQmlDebugService::blockingMode()) { + // let's wait for first message ... + d->initializeCondition.wait(&d->initializeMutex); } } @@ -139,6 +145,10 @@ void QV8ProfilerService::stateAboutToBeChanged(QQmlDebugService::State newState) Q_ARG(QString, title)); } QMetaObject::invokeMethod(this, "sendProfilingData", Qt::BlockingQueuedConnection); + } else { + // wake up constructor in blocking mode + // (we might got disabled before first message arrived) + d->initializeCondition.wakeAll(); } } @@ -152,6 +162,8 @@ void QV8ProfilerService::messageReceived(const QByteArray &message) QByteArray title; ds >> command >> option; + QMutexLocker lock(&d->initializeMutex); + if (command == "V8PROFILER") { ds >> title; QString titleStr = QString::fromUtf8(title); @@ -172,6 +184,9 @@ void QV8ProfilerService::messageReceived(const QByteArray &message) } } + // wake up constructor in blocking mode + d->initializeCondition.wakeAll(); + QQmlDebugService::messageReceived(message); } |