summaryrefslogtreecommitdiff
path: root/src/plugins/projectexplorer
diff options
context:
space:
mode:
authorMarcus Tillmanns <marcus.tillmanns@qt.io>2022-11-08 15:08:21 +0100
committerMarcus Tillmanns <marcus.tillmanns@qt.io>2022-11-09 08:33:37 +0000
commit06838e3e5e41f1f090fdd016c736bb91241cd5b3 (patch)
tree1b8a1bb20669de77a93be1d8dee5896528c30473 /src/plugins/projectexplorer
parentdf946c77dc49be5e697f1b47bb9eb658ce847892 (diff)
downloadqt-creator-06838e3e5e41f1f090fdd016c736bb91241cd5b3.tar.gz
ProjectExplorer: Fix potential race condition
When using BuildStep::runImpl() it was possible for the async part to still be running while the BuildStep is already deleted. This change returns the Future so that users can wait for it to finish. Change-Id: I27c0fc8741c59851c5ab8f5cb858fbcda923c14d Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Diffstat (limited to 'src/plugins/projectexplorer')
-rw-r--r--src/plugins/projectexplorer/buildstep.cpp6
-rw-r--r--src/plugins/projectexplorer/buildstep.h3
2 files changed, 6 insertions, 3 deletions
diff --git a/src/plugins/projectexplorer/buildstep.cpp b/src/plugins/projectexplorer/buildstep.cpp
index 070e8f3b54..4088ce3d0b 100644
--- a/src/plugins/projectexplorer/buildstep.cpp
+++ b/src/plugins/projectexplorer/buildstep.cpp
@@ -295,7 +295,7 @@ QVariant BuildStep::data(Id id) const
immutable steps are run. The default implementation returns \c false.
*/
-void BuildStep::runInThread(const std::function<bool()> &syncImpl)
+QFuture<bool> BuildStep::runInThread(const std::function<bool()> &syncImpl)
{
m_runInGuiThread = false;
m_cancelFlag = false;
@@ -304,7 +304,9 @@ void BuildStep::runInThread(const std::function<bool()> &syncImpl)
emit finished(watcher->result());
watcher->deleteLater();
});
- watcher->setFuture(Utils::runAsync(syncImpl));
+ auto future = Utils::runAsync(syncImpl);
+ watcher->setFuture(future);
+ return future;
}
std::function<bool ()> BuildStep::cancelChecker() const
diff --git a/src/plugins/projectexplorer/buildstep.h b/src/plugins/projectexplorer/buildstep.h
index 79ae4a60bc..0f5def37bd 100644
--- a/src/plugins/projectexplorer/buildstep.h
+++ b/src/plugins/projectexplorer/buildstep.h
@@ -10,6 +10,7 @@
#include <utils/qtcassert.h>
+#include <QFuture>
#include <QWidget>
#include <atomic>
@@ -117,7 +118,7 @@ signals:
protected:
virtual QWidget *createConfigWidget();
- void runInThread(const std::function<bool()> &syncImpl);
+ QFuture<bool> runInThread(const std::function<bool()> &syncImpl);
std::function<bool()> cancelChecker() const;
bool isCanceled() const;