Commit b851b57e authored by Tobias Hunger's avatar Tobias Hunger

Utils::ShellCommand: Force fully synchronous execution from UI thread

Force runCommand when run from the UI thread to do fully synchronous
operations. This prevents two event loops in one thread with (sometimes)
interesting side effects.

This also stops signals from being sent while the process is running,
but the remaining users seem to be able to handle that.

Change-Id: Id5eb9868b660419987730c60e3fbfb4cbced1218
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent 05b5b616
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include <QSharedPointer> #include <QSharedPointer>
#include <QStringList> #include <QStringList>
#include <QTextCodec> #include <QTextCodec>
#include <QThread>
#include <QVariant> #include <QVariant>
/*! /*!
...@@ -326,7 +327,7 @@ Utils::SynchronousProcessResponse ShellCommand::runCommand(const Utils::FileName ...@@ -326,7 +327,7 @@ Utils::SynchronousProcessResponse ShellCommand::runCommand(const Utils::FileName
if (!(d->m_flags & SuppressCommandLogging)) if (!(d->m_flags & SuppressCommandLogging))
proxy->appendCommand(dir, binary, arguments); proxy->appendCommand(dir, binary, arguments);
if (d->m_flags & FullySynchronously) if (d->m_flags & FullySynchronously || QThread::currentThread() == QCoreApplication::instance()->thread())
response = runFullySynchronous(binary, arguments, proxy.data(), timeoutS, dir, interpreter); response = runFullySynchronous(binary, arguments, proxy.data(), timeoutS, dir, interpreter);
else else
response = runSynchronous(binary, arguments, proxy.data(), timeoutS, dir, interpreter); response = runSynchronous(binary, arguments, proxy.data(), timeoutS, dir, interpreter);
......
...@@ -140,6 +140,9 @@ public: ...@@ -140,6 +140,9 @@ public:
void setOutputProxyFactory(const std::function<OutputProxy *()> &factory); void setOutputProxyFactory(const std::function<OutputProxy *()> &factory);
// This is called once per job in a thread.
// When called from the UI thread it will execute fully synchronously, so no signals will
// be triggered!
virtual SynchronousProcessResponse runCommand(const FileName &binary, const QStringList &arguments, virtual SynchronousProcessResponse runCommand(const FileName &binary, const QStringList &arguments,
int timeoutS, int timeoutS,
const QString &workingDirectory = QString(), const QString &workingDirectory = QString(),
...@@ -162,10 +165,13 @@ protected: ...@@ -162,10 +165,13 @@ protected:
private: private:
void run(QFutureInterface<void> &future); void run(QFutureInterface<void> &future);
// Run without a event loop in fully blocking mode. No signals will be delivered.
SynchronousProcessResponse runFullySynchronous(const FileName &binary, const QStringList &arguments, SynchronousProcessResponse runFullySynchronous(const FileName &binary, const QStringList &arguments,
OutputProxy *proxy, OutputProxy *proxy,
int timeoutS, const QString &workingDirectory, int timeoutS, const QString &workingDirectory,
const ExitCodeInterpreter &interpreter = defaultExitCodeInterpreter); const ExitCodeInterpreter &interpreter = defaultExitCodeInterpreter);
// Run with an event loop. Signals will be delivered.
SynchronousProcessResponse runSynchronous(const FileName &binary, const QStringList &arguments, SynchronousProcessResponse runSynchronous(const FileName &binary, const QStringList &arguments,
OutputProxy *proxy, OutputProxy *proxy,
int timeoutS, const QString &workingDirectory, int timeoutS, const QString &workingDirectory,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment