Core: Restrict ProcessReaper to QtcProcesses

Long term plan is to make that part of QtcProcess proper (removing
the QProcess base of QtcProcess, have a QtcProcess * in the private
data instead, and reap that e.g. on QtcProcess instance destruction.

Change-Id: Ic7e60fdd69f56e8e22bad3dfbc246e7de2fe9cd4
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2021-05-25 16:44:20 +02:00
parent 447a719fe2
commit decf59120b
2 changed files with 11 additions and 25 deletions

View File

@@ -34,31 +34,17 @@
#include <QThread>
#include <QTimer>
using namespace Utils;
namespace Core {
namespace Internal {
static ProcessReapers *d = nullptr;
static void killProcess(QProcess *process)
{
if (auto qtcProcess = qobject_cast<Utils::QtcProcess*>(process))
qtcProcess->kill();
else
process->kill();
}
static void terminateProcess(QProcess *process)
{
if (auto qtcProcess = qobject_cast<Utils::QtcProcess*>(process))
qtcProcess->terminate();
else
process->terminate();
}
class ProcessReaper final : public QObject
{
public:
ProcessReaper(QProcess *p, int timeoutMs);
ProcessReaper(QtcProcess *p, int timeoutMs);
~ProcessReaper() final;
int timeoutMs() const;
@@ -67,12 +53,12 @@ public:
private:
mutable QTimer m_iterationTimer;
QProcess *m_process;
QtcProcess *m_process;
int m_emergencyCounter = 0;
QProcess::ProcessState m_lastState = QProcess::NotRunning;
};
ProcessReaper::ProcessReaper(QProcess *p, int timeoutMs) : m_process(p)
ProcessReaper::ProcessReaper(QtcProcess *p, int timeoutMs) : m_process(p)
{
d->m_reapers.append(this);
@@ -113,12 +99,12 @@ void ProcessReaper::nextIteration()
if (state == QProcess::Starting) {
if (m_lastState == QProcess::Starting)
killProcess(m_process);
m_process->kill();
} else if (state == QProcess::Running) {
if (m_lastState == QProcess::Running)
killProcess(m_process);
m_process->kill();
else
terminateProcess(m_process);
m_process->terminate();
}
m_lastState = state;
@@ -165,7 +151,7 @@ ProcessReapers::~ProcessReapers()
namespace Reaper {
void reap(QProcess *process, int timeoutMs)
void reap(QtcProcess *process, int timeoutMs)
{
if (!process)
return;

View File

@@ -27,12 +27,12 @@
#include "core_global.h"
QT_FORWARD_DECLARE_CLASS(QProcess);
namespace Utils { class QtcProcess; }
namespace Core {
namespace Reaper {
CORE_EXPORT void reap(QProcess *p, int timeoutMs = 500);
CORE_EXPORT void reap(Utils::QtcProcess *p, int timeoutMs = 500);
} // namespace Reaper
} // namespace Core