ProcessBlockingInterface: Change signature of waitForSignal()

Change the arg to QDeadlineTimer type.

Change-Id: I7087648fd4f248b0b5024dc0d51d65171037934d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2024-01-22 19:35:39 +01:00
parent 63fc22e274
commit 00ba645fe1
4 changed files with 21 additions and 21 deletions

View File

@@ -300,11 +300,11 @@ void CallerHandle::setProcessSetupData(ProcessSetupData *setup)
m_setup = setup; m_setup = setup;
} }
bool CallerHandle::waitForSignal(SignalType signalType, int msecs) bool CallerHandle::waitForSignal(SignalType signalType, QDeadlineTimer timeout)
{ {
QTC_ASSERT(isCalledFromCallersThread(), return false); QTC_ASSERT(isCalledFromCallersThread(), return false);
QTC_ASSERT(m_launcherHandle, return false); QTC_ASSERT(m_launcherHandle, return false);
return m_launcherHandle->waitForSignal(signalType, msecs); return m_launcherHandle->waitForSignal(signalType, timeout);
} }
// Called from caller's or launcher's thread. // Called from caller's or launcher's thread.
@@ -322,14 +322,13 @@ bool CallerHandle::isCalledFromLaunchersThread() const
} }
// Called from caller's thread exclusively. // Called from caller's thread exclusively.
bool LauncherHandle::waitForSignal(CallerHandle::SignalType newSignal, int msecs) bool LauncherHandle::waitForSignal(CallerHandle::SignalType newSignal, QDeadlineTimer timeout)
{ {
QTC_ASSERT(!isCalledFromLaunchersThread(), return false); QTC_ASSERT(!isCalledFromLaunchersThread(), return false);
QDeadlineTimer deadline(msecs);
while (true) { while (true) {
if (deadline.hasExpired()) if (timeout.hasExpired())
break; break;
if (!doWaitForSignal(deadline)) if (!doWaitForSignal(timeout))
break; break;
// Matching (or Done) signal was flushed // Matching (or Done) signal was flushed
if (m_callerHandle->flushFor(newSignal)) if (m_callerHandle->flushFor(newSignal))

View File

@@ -51,7 +51,7 @@ public:
LauncherHandle *launcherHandle() const { return m_launcherHandle; } LauncherHandle *launcherHandle() const { return m_launcherHandle; }
void setLauncherHandle(LauncherHandle *handle) { QMutexLocker locker(&m_mutex); m_launcherHandle = handle; } void setLauncherHandle(LauncherHandle *handle) { QMutexLocker locker(&m_mutex); m_launcherHandle = handle; }
bool waitForSignal(CallerHandle::SignalType signalType, int msecs); bool waitForSignal(CallerHandle::SignalType signalType, QDeadlineTimer timeout);
// Returns the list of flushed signals. // Returns the list of flushed signals.
void flush(); void flush();
@@ -132,7 +132,7 @@ public:
// Called from caller's thread, moved to launcher's thread afterwards. // Called from caller's thread, moved to launcher's thread afterwards.
LauncherHandle(quintptr token) : m_token(token) {} LauncherHandle(quintptr token) : m_token(token) {}
// Called from caller's thread exclusively. // Called from caller's thread exclusively.
bool waitForSignal(CallerHandle::SignalType newSignal, int msecs); bool waitForSignal(CallerHandle::SignalType newSignal, QDeadlineTimer timeout);
CallerHandle *callerHandle() const { return m_callerHandle; } CallerHandle *callerHandle() const { return m_callerHandle; }
void setCallerHandle(CallerHandle *handle) { QMutexLocker locker(&m_mutex); m_callerHandle = handle; } void setCallerHandle(CallerHandle *handle) { QMutexLocker locker(&m_mutex); m_callerHandle = handle; }

View File

@@ -565,7 +565,7 @@ public:
ProcessLauncherBlockingImpl(CallerHandle *caller) : m_caller(caller) {} ProcessLauncherBlockingImpl(CallerHandle *caller) : m_caller(caller) {}
private: private:
bool waitForSignal(ProcessSignalType signalType, int msecs) final bool waitForSignal(ProcessSignalType signalType, QDeadlineTimer timeout) final
{ {
// TODO: Remove CallerHandle::SignalType // TODO: Remove CallerHandle::SignalType
const CallerHandle::SignalType type = [signalType] { const CallerHandle::SignalType type = [signalType] {
@@ -580,7 +580,7 @@ private:
QTC_CHECK(false); QTC_CHECK(false);
return CallerHandle::SignalType::NoSignal; return CallerHandle::SignalType::NoSignal;
}(); }();
return m_caller->waitForSignal(type, msecs); return m_caller->waitForSignal(type, timeout);
} }
CallerHandle *m_caller = nullptr; CallerHandle *m_caller = nullptr;
@@ -718,7 +718,7 @@ public:
ProcessInterfaceHandler(GeneralProcessBlockingImpl *caller, ProcessInterface *process); ProcessInterfaceHandler(GeneralProcessBlockingImpl *caller, ProcessInterface *process);
// Called from caller's thread exclusively. // Called from caller's thread exclusively.
bool waitForSignal(ProcessSignalType newSignal, int msecs); bool waitForSignal(ProcessSignalType newSignal, QDeadlineTimer timeout);
void moveToCallerThread(); void moveToCallerThread();
private: private:
@@ -753,7 +753,7 @@ public:
private: private:
// Called from caller's thread exclusively // Called from caller's thread exclusively
bool waitForSignal(ProcessSignalType newSignal, int msecs) final; bool waitForSignal(ProcessSignalType newSignal, QDeadlineTimer timeout) final;
QList<ProcessInterfaceSignal *> takeAllSignals(); QList<ProcessInterfaceSignal *> takeAllSignals();
QList<ProcessInterfaceSignal *> takeSignalsFor(ProcessSignalType signalType); QList<ProcessInterfaceSignal *> takeSignalsFor(ProcessSignalType signalType);
@@ -873,13 +873,12 @@ ProcessInterfaceHandler::ProcessInterfaceHandler(GeneralProcessBlockingImpl *cal
} }
// Called from caller's thread exclusively. // Called from caller's thread exclusively.
bool ProcessInterfaceHandler::waitForSignal(ProcessSignalType newSignal, int msecs) bool ProcessInterfaceHandler::waitForSignal(ProcessSignalType newSignal, QDeadlineTimer timeout)
{ {
QDeadlineTimer deadline(msecs);
while (true) { while (true) {
if (deadline.hasExpired()) if (timeout.hasExpired())
break; break;
if (!doWaitForSignal(deadline)) if (!doWaitForSignal(timeout))
break; break;
// Matching (or Done) signal was flushed // Matching (or Done) signal was flushed
if (m_caller->flushFor(newSignal)) if (m_caller->flushFor(newSignal))
@@ -957,7 +956,7 @@ GeneralProcessBlockingImpl::GeneralProcessBlockingImpl(ProcessPrivate *parent)
// +- ProcessInterface // +- ProcessInterface
} }
bool GeneralProcessBlockingImpl::waitForSignal(ProcessSignalType newSignal, int msecs) bool GeneralProcessBlockingImpl::waitForSignal(ProcessSignalType newSignal, QDeadlineTimer timeout)
{ {
m_processHandler->setParent(nullptr); m_processHandler->setParent(nullptr);
@@ -968,7 +967,7 @@ bool GeneralProcessBlockingImpl::waitForSignal(ProcessSignalType newSignal, int
// the caller here is blocked, so all signals should be buffered and we are going // the caller here is blocked, so all signals should be buffered and we are going
// to flush them from inside waitForSignal(). // to flush them from inside waitForSignal().
m_processHandler->moveToThread(&thread); m_processHandler->moveToThread(&thread);
const bool result = m_processHandler->waitForSignal(newSignal, msecs); const bool result = m_processHandler->waitForSignal(newSignal, timeout);
m_processHandler->moveToCallerThread(); m_processHandler->moveToCallerThread();
m_processHandler->setParent(this); m_processHandler->setParent(this);
thread.quit(); thread.quit();
@@ -1068,11 +1067,12 @@ bool ProcessPrivate::waitForSignal(ProcessSignalType newSignal, QDeadlineTimer t
const bool needsSplit = m_killTimer.isActive() && timeout > currentKillTimeout; const bool needsSplit = m_killTimer.isActive() && timeout > currentKillTimeout;
const QDeadlineTimer mainTimeout = needsSplit ? currentKillTimeout : timeout; const QDeadlineTimer mainTimeout = needsSplit ? currentKillTimeout : timeout;
bool result = m_blockingInterface->waitForSignal(newSignal, mainTimeout.remainingTime()); bool result = m_blockingInterface->waitForSignal(newSignal,
duration_cast<milliseconds>(mainTimeout.remainingTimeAsDuration()));
if (!result && needsSplit) { if (!result && needsSplit) {
m_killTimer.stop(); m_killTimer.stop();
sendControlSignal(ControlSignal::Kill); sendControlSignal(ControlSignal::Kill);
result = m_blockingInterface->waitForSignal(newSignal, timeout.remainingTime()); result = m_blockingInterface->waitForSignal(newSignal, timeout);
} }
return result; return result;
} }

View File

@@ -9,6 +9,7 @@
#include "commandline.h" #include "commandline.h"
#include "processenums.h" #include "processenums.h"
#include <QDeadlineTimer>
#include <QProcess> #include <QProcess>
#include <QSize> #include <QSize>
@@ -125,7 +126,7 @@ private:
// - Started is being called only in Starting state. // - Started is being called only in Starting state.
// - ReadyRead is being called in Starting or Running state. // - ReadyRead is being called in Starting or Running state.
// - Done is being called in Starting or Running state. // - Done is being called in Starting or Running state.
virtual bool waitForSignal(ProcessSignalType signalType, int msecs) = 0; virtual bool waitForSignal(ProcessSignalType signalType, QDeadlineTimer timeout) = 0;
friend class Internal::ProcessPrivate; friend class Internal::ProcessPrivate;
}; };