Utils: Slim down private ProcessReaper interface

Change-Id: Idd5669b9ed525148426b85bbbc9a2818877f2707
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
This commit is contained in:
hjk
2021-11-26 18:40:56 +01:00
parent ce82c058df
commit 64ac719ff8
2 changed files with 7 additions and 10 deletions

View File

@@ -60,9 +60,11 @@ private:
QProcess::ProcessState m_lastState = QProcess::NotRunning;
};
static QList<Reaper *> g_reapers;
Reaper::Reaper(QProcess *p, int timeoutMs) : m_process(p)
{
ProcessReaper::instance()->m_reapers.append(this);
g_reapers.append(this);
m_iterationTimer.setInterval(timeoutMs);
m_iterationTimer.setSingleShot(true);
@@ -73,7 +75,7 @@ Reaper::Reaper(QProcess *p, int timeoutMs) : m_process(p)
Reaper::~Reaper()
{
ProcessReaper::instance()->m_reapers.removeOne(this);
g_reapers.removeOne(this);
}
int Reaper::timeoutMs() const
@@ -144,12 +146,12 @@ void Reaper::nextIteration()
ProcessReaper::~ProcessReaper()
{
while (!m_reapers.isEmpty()) {
while (!Internal::g_reapers.isEmpty()) {
int alreadyWaited = 0;
QList<Internal::Reaper *> toDelete;
// push reapers along:
for (Internal::Reaper *pr : qAsConst(m_reapers)) {
for (Internal::Reaper *pr : qAsConst(Internal::g_reapers)) {
const int timeoutMs = pr->timeoutMs();
if (alreadyWaited < timeoutMs) {
const unsigned long toSleep = static_cast<unsigned long>(timeoutMs - alreadyWaited);

View File

@@ -29,26 +29,21 @@
#include "singleton.h"
#include <QList>
QT_BEGIN_NAMESPACE
class QProcess;
QT_END_NAMESPACE
namespace Utils {
namespace Internal { class Reaper; }
class QTCREATOR_UTILS_EXPORT ProcessReaper final
: public SingletonWithOptionalDependencies<ProcessReaper>
{
public:
static void reap(QProcess *process, int timeoutMs = 500);
private:
ProcessReaper() = default;
~ProcessReaper();
QList<Internal::Reaper *> m_reapers;
friend class Internal::Reaper;
friend class SingletonWithOptionalDependencies<ProcessReaper>;
};