QtcProcess: Use Utils::Guard instead of self made substitute

Change-Id: I36b6db25998b5c34c2c96cfb5dc8c60537dbb7b6
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Jarek Kobus
2022-05-24 09:08:41 +02:00
parent 6fc98722e2
commit f9433c79b7

View File

@@ -27,6 +27,7 @@
#include "algorithm.h" #include "algorithm.h"
#include "commandline.h" #include "commandline.h"
#include "guard.h"
#include "hostosinfo.h" #include "hostosinfo.h"
#include "launcherinterface.h" #include "launcherinterface.h"
#include "launchersocket.h" #include "launchersocket.h"
@@ -667,7 +668,6 @@ public:
QList<ProcessInterfaceSignal *> m_signals; QList<ProcessInterfaceSignal *> m_signals;
// ======================================= // =======================================
QProcess::ProcessState m_state = QProcess::NotRunning; QProcess::ProcessState m_state = QProcess::NotRunning;
qint64 m_processId = 0; qint64 m_processId = 0;
qint64 m_applicationMainThreadId = 0; qint64 m_applicationMainThreadId = 0;
@@ -685,18 +685,9 @@ public:
bool m_timeOutMessageBoxEnabled = false; bool m_timeOutMessageBoxEnabled = false;
bool m_waitingForUser = false; bool m_waitingForUser = false;
class Guard { Guard m_guard;
public:
Guard(int &guard) : m_guard(guard) { ++guard; }
~Guard() { --m_guard; }
private:
int &m_guard;
};
int m_callStackGuard = 0;
}; };
#define CALL_STACK_GUARD() Guard guard(m_callStackGuard)
ProcessInterfaceHandler::ProcessInterfaceHandler(QtcProcessPrivate *caller, ProcessInterfaceHandler::ProcessInterfaceHandler(QtcProcessPrivate *caller,
ProcessInterface *process) ProcessInterface *process)
: m_caller(caller) : m_caller(caller)
@@ -980,7 +971,7 @@ QtcProcess::QtcProcess(QObject *parent)
QtcProcess::~QtcProcess() QtcProcess::~QtcProcess()
{ {
QTC_ASSERT(d->m_callStackGuard == 0, qWarning("Deleting QtcProcess instance directly from " QTC_ASSERT(!d->m_guard.isLocked(), qWarning("Deleting QtcProcess instance directly from "
"one of its signal handlers will lead to crash!")); "one of its signal handlers will lead to crash!"));
delete d; delete d;
} }
@@ -1962,37 +1953,37 @@ void QtcProcessPrivate::handleError()
void QtcProcessPrivate::emitStarted() void QtcProcessPrivate::emitStarted()
{ {
CALL_STACK_GUARD(); GuardLocker locker(m_guard);
emit q->started(); emit q->started();
} }
void QtcProcessPrivate::emitFinished() void QtcProcessPrivate::emitFinished()
{ {
CALL_STACK_GUARD(); GuardLocker locker(m_guard);
emit q->finished(); emit q->finished();
} }
void QtcProcessPrivate::emitDone() void QtcProcessPrivate::emitDone()
{ {
CALL_STACK_GUARD(); GuardLocker locker(m_guard);
emit q->done(); emit q->done();
} }
void QtcProcessPrivate::emitErrorOccurred(QProcess::ProcessError error) void QtcProcessPrivate::emitErrorOccurred(QProcess::ProcessError error)
{ {
CALL_STACK_GUARD(); GuardLocker locker(m_guard);
emit q->errorOccurred(error); emit q->errorOccurred(error);
} }
void QtcProcessPrivate::emitReadyReadStandardOutput() void QtcProcessPrivate::emitReadyReadStandardOutput()
{ {
CALL_STACK_GUARD(); GuardLocker locker(m_guard);
emit q->readyReadStandardOutput(); emit q->readyReadStandardOutput();
} }
void QtcProcessPrivate::emitReadyReadStandardError() void QtcProcessPrivate::emitReadyReadStandardError()
{ {
CALL_STACK_GUARD(); GuardLocker locker(m_guard);
emit q->readyReadStandardError(); emit q->readyReadStandardError();
} }