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

View File

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