forked from qt-creator/qt-creator
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:
@@ -34,31 +34,17 @@
|
|||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
|
||||||
|
using namespace Utils;
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
static ProcessReapers *d = nullptr;
|
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
|
class ProcessReaper final : public QObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
ProcessReaper(QProcess *p, int timeoutMs);
|
ProcessReaper(QtcProcess *p, int timeoutMs);
|
||||||
~ProcessReaper() final;
|
~ProcessReaper() final;
|
||||||
|
|
||||||
int timeoutMs() const;
|
int timeoutMs() const;
|
||||||
@@ -67,12 +53,12 @@ public:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
mutable QTimer m_iterationTimer;
|
mutable QTimer m_iterationTimer;
|
||||||
QProcess *m_process;
|
QtcProcess *m_process;
|
||||||
int m_emergencyCounter = 0;
|
int m_emergencyCounter = 0;
|
||||||
QProcess::ProcessState m_lastState = QProcess::NotRunning;
|
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);
|
d->m_reapers.append(this);
|
||||||
|
|
||||||
@@ -113,12 +99,12 @@ void ProcessReaper::nextIteration()
|
|||||||
|
|
||||||
if (state == QProcess::Starting) {
|
if (state == QProcess::Starting) {
|
||||||
if (m_lastState == QProcess::Starting)
|
if (m_lastState == QProcess::Starting)
|
||||||
killProcess(m_process);
|
m_process->kill();
|
||||||
} else if (state == QProcess::Running) {
|
} else if (state == QProcess::Running) {
|
||||||
if (m_lastState == QProcess::Running)
|
if (m_lastState == QProcess::Running)
|
||||||
killProcess(m_process);
|
m_process->kill();
|
||||||
else
|
else
|
||||||
terminateProcess(m_process);
|
m_process->terminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
m_lastState = state;
|
m_lastState = state;
|
||||||
@@ -165,7 +151,7 @@ ProcessReapers::~ProcessReapers()
|
|||||||
|
|
||||||
namespace Reaper {
|
namespace Reaper {
|
||||||
|
|
||||||
void reap(QProcess *process, int timeoutMs)
|
void reap(QtcProcess *process, int timeoutMs)
|
||||||
{
|
{
|
||||||
if (!process)
|
if (!process)
|
||||||
return;
|
return;
|
||||||
|
@@ -27,12 +27,12 @@
|
|||||||
|
|
||||||
#include "core_global.h"
|
#include "core_global.h"
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QProcess);
|
namespace Utils { class QtcProcess; }
|
||||||
|
|
||||||
namespace Core {
|
namespace Core {
|
||||||
namespace Reaper {
|
namespace Reaper {
|
||||||
|
|
||||||
CORE_EXPORT void reap(QProcess *p, int timeoutMs = 500);
|
CORE_EXPORT void reap(Utils::QtcProcess *p, int timeoutMs = 500);
|
||||||
|
|
||||||
} // namespace Reaper
|
} // namespace Reaper
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
Reference in New Issue
Block a user