OSDN Git Service

reuse PID as serial in QProcessManager
authorIvailo Monev <xakepa10@gmail.com>
Wed, 21 Oct 2020 18:11:05 +0000 (21:11 +0300)
committerIvailo Monev <xakepa10@gmail.com>
Wed, 21 Oct 2020 18:11:05 +0000 (21:11 +0300)
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
src/core/io/qprocess.cpp
src/core/io/qprocess_p.h
src/core/io/qprocess_unix.cpp

index 9045bc6..85b0cd2 100644 (file)
@@ -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
index b320d8d..620ee53 100644 (file)
@@ -271,7 +271,6 @@ public:
     int exitCode;
     QProcess::ExitStatus exitStatus;
     bool crashed;
-    int serial;
 
     bool waitForStarted(int msecs = 30000);
     bool waitForReadyRead(int msecs = 30000);
index 14876a0..b975553 100644 (file)
@@ -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<int, QProcessInfo *> children;
+    QHash<pid_t, QProcessInfo *> 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<int, QProcessInfo *>::const_iterator it = children.constBegin();
+    QHash<pid_t, QProcessInfo *>::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)