summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Poulain <benjamin.poulain@nokia.com>2009-08-06 14:37:07 (GMT)
committerBenjamin Poulain <benjamin.poulain@nokia.com>2009-08-06 15:16:18 (GMT)
commita488f0784b265d350441f5e38dc9021e9c2a50fc (patch)
tree12b483cd7225e2541838811230626f726cfdc61d
parent8bd1ac790c9b336d64e407a94b1ae6a4e195fc30 (diff)
downloadQt-a488f0784b265d350441f5e38dc9021e9c2a50fc.zip
Qt-a488f0784b265d350441f5e38dc9021e9c2a50fc.tar.gz
Qt-a488f0784b265d350441f5e38dc9021e9c2a50fc.tar.bz2
Fix a bug in QProcess. QProcess was not reentrant on Unix
QProcess is supposed to be reentrant but was not on Unix. The constructor of QProcessManager could be exectued several time when QProcess is created. The construction is now protected by a mutex. Task-number: 254246 Reviewed-by: Olivier Goffart
-rw-r--r--src/corelib/io/qprocess_unix.cpp12
-rw-r--r--tests/auto/qprocess/tst_qprocess.cpp2
2 files changed, 12 insertions, 2 deletions
diff --git a/src/corelib/io/qprocess_unix.cpp b/src/corelib/io/qprocess_unix.cpp
index 607b734..168eac2 100644
--- a/src/corelib/io/qprocess_unix.cpp
+++ b/src/corelib/io/qprocess_unix.cpp
@@ -162,7 +162,17 @@ private:
QMap<int, QProcessInfo *> children;
};
-Q_GLOBAL_STATIC(QProcessManager, processManager)
+
+Q_GLOBAL_STATIC(QMutex, processManagerGlobalMutex)
+
+static QProcessManager *processManager() {
+ // The constructor of QProcessManager should be called only once
+ // so we cannot use Q_GLOBAL_STATIC directly for QProcessManager
+ QMutex *mutex = processManagerGlobalMutex();
+ QMutexLocker locker(mutex);
+ static QProcessManager processManager;
+ return &processManager;
+}
QProcessManager::QProcessManager()
{
diff --git a/tests/auto/qprocess/tst_qprocess.cpp b/tests/auto/qprocess/tst_qprocess.cpp
index d235dff..1ffa360 100644
--- a/tests/auto/qprocess/tst_qprocess.cpp
+++ b/tests/auto/qprocess/tst_qprocess.cpp
@@ -1224,7 +1224,7 @@ private:
//-----------------------------------------------------------------------------
void tst_QProcess::processInAThread()
{
- for (int i = 0; i < 3; ++i) {
+ for (int i = 0; i < 10; ++i) {
TestThread thread;
thread.start();
QVERIFY(thread.wait(10000));