From 0f3ff25f0b157ac6363fa924dec8075cc2ee82e9 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 21 Oct 2020 21:11:05 +0300 Subject: [PATCH] reuse PID as serial in QProcessManager Signed-off-by: Ivailo Monev --- src/core/io/qprocess.cpp | 2 -- src/core/io/qprocess_p.h | 1 - src/core/io/qprocess_unix.cpp | 13 ++++--------- 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/core/io/qprocess.cpp b/src/core/io/qprocess.cpp index 9045bc66b..85b0cd281 100644 --- a/src/core/io/qprocess.cpp +++ b/src/core/io/qprocess.cpp @@ -736,7 +736,6 @@ QProcessPrivate::QProcessPrivate() dying = false; emittedReadyRead = false; emittedBytesWritten = false; - serial = 0; } /*! \internal @@ -787,7 +786,6 @@ void QProcessPrivate::cleanup() destroyPipe(stdinChannel.pipe); destroyPipe(childStartedPipe); destroyPipe(deathPipe); - serial = 0; } /*! \internal diff --git a/src/core/io/qprocess_p.h b/src/core/io/qprocess_p.h index b320d8d42..620ee5300 100644 --- a/src/core/io/qprocess_p.h +++ b/src/core/io/qprocess_p.h @@ -271,7 +271,6 @@ public: int exitCode; QProcess::ExitStatus exitStatus; bool crashed; - int serial; bool waitForStarted(int msecs = 30000); bool waitForReadyRead(int msecs = 30000); diff --git a/src/core/io/qprocess_unix.cpp b/src/core/io/qprocess_unix.cpp index 14876a005..b9755534a 100644 --- a/src/core/io/qprocess_unix.cpp +++ b/src/core/io/qprocess_unix.cpp @@ -137,7 +137,6 @@ struct QProcessInfo { int deathPipe; int exitResult; pid_t pid; - int serialNumber; }; class QProcessManager : public QThread @@ -156,7 +155,7 @@ public: private: QMutex mutex; - QHash children; + QHash children; }; @@ -259,7 +258,7 @@ void QProcessManager::catchDeadChildren() // try to catch all children whose pid we have registered, and whose // deathPipe is still valid (i.e, we have not already notified it). - QHash::const_iterator it = children.constBegin(); + QHash::const_iterator it = children.constBegin(); while (it != children.constEnd()) { // notify all children that they may have died. they need to run // waitpid() in their own thread. @@ -273,8 +272,6 @@ void QProcessManager::catchDeadChildren() } } -static QAtomicInt idCounter = QAtomicInt(1); - void QProcessManager::add(pid_t pid, QProcess *process) { // locked by startProcess() @@ -289,16 +286,14 @@ void QProcessManager::add(pid_t pid, QProcess *process) info->exitResult = 0; info->pid = pid; - int serial = idCounter.fetchAndAddRelaxed(1); - process->d_func()->serial = serial; - children.insert(serial, info); + children.insert(pid, info); } void QProcessManager::remove(QProcess *process) { QMutexLocker locker(&mutex); - int serial = process->d_func()->serial; + pid_t serial = process->d_func()->pid; QProcessInfo *info = children.take(serial); #if defined (QPROCESS_DEBUG) if (info) -- 2.11.0