Use Utils::FutureSynchronizer instead of QFutureSynchronizer

Change-Id: Iecfa676f58e5ca82be7c9c94233dcc8d3654c2d7
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Jarek Kobus
2021-05-12 15:12:48 +02:00
parent 3823b0af5f
commit 91f136ef3a
16 changed files with 36 additions and 64 deletions

View File

@@ -31,9 +31,9 @@
#include <cpptools/builtineditordocumentprocessor.h> #include <cpptools/builtineditordocumentprocessor.h>
#include <cpptools/semantichighlighter.h> #include <cpptools/semantichighlighter.h>
#include <utils/futuresynchronizer.h>
#include <utils/id.h> #include <utils/id.h>
#include <QFutureSynchronizer>
#include <QFutureWatcher> #include <QFutureWatcher>
#include <QTimer> #include <QTimer>
@@ -146,7 +146,7 @@ private:
QVector<ClangBackEnd::TokenInfoContainer> m_tokenInfos; QVector<ClangBackEnd::TokenInfoContainer> m_tokenInfos;
CppTools::SemanticHighlighter m_semanticHighlighter; CppTools::SemanticHighlighter m_semanticHighlighter;
CppTools::BuiltinEditorDocumentProcessor m_builtinProcessor; CppTools::BuiltinEditorDocumentProcessor m_builtinProcessor;
QFutureSynchronizer<void> m_parserSynchronizer; Utils::FutureSynchronizer m_parserSynchronizer;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -327,7 +327,7 @@ void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *pr
auto future = Utils::runAsync(&Internal::generateCompilationDB, projectInfo, auto future = Utils::runAsync(&Internal::generateCompilationDB, projectInfo,
CompilationDbPurpose::CodeModel); CompilationDbPurpose::CodeModel);
generatorWatcher->setFuture(future); generatorWatcher->setFuture(future);
m_generatorSynchronizer.addFuture(QFuture<void>(future)); m_generatorSynchronizer.addFuture(future);
} }
ClangdClient *ClangModelManagerSupport::clientForProject( ClangdClient *ClangModelManagerSupport::clientForProject(

View File

@@ -30,9 +30,9 @@
#include <cpptools/cppmodelmanagersupport.h> #include <cpptools/cppmodelmanagersupport.h>
#include <utils/futuresynchronizer.h>
#include <utils/id.h> #include <utils/id.h>
#include <QFutureSynchronizer>
#include <QObject> #include <QObject>
#include <memory> #include <memory>
@@ -135,7 +135,7 @@ private:
std::unique_ptr<CppTools::RefactoringEngineInterface> m_refactoringEngine; std::unique_ptr<CppTools::RefactoringEngineInterface> m_refactoringEngine;
QHash<ProjectExplorer::Project *, ClangProjectSettings *> m_projectSettings; QHash<ProjectExplorer::Project *, ClangProjectSettings *> m_projectSettings;
QFutureSynchronizer<void> m_generatorSynchronizer; Utils::FutureSynchronizer m_generatorSynchronizer;
}; };
class ClangModelManagerSupportProvider : public CppTools::ModelManagerSupportProvider class ClangModelManagerSupportProvider : public CppTools::ModelManagerSupportProvider

View File

@@ -33,10 +33,9 @@
#include <projectexplorer/buildsystem.h> #include <projectexplorer/buildsystem.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/futuresynchronizer.h>
#include <utils/temporarydirectory.h> #include <utils/temporarydirectory.h>
#include <QFutureSynchronizer>
namespace ProjectExplorer { class ExtraCompiler; } namespace ProjectExplorer { class ExtraCompiler; }
namespace CppTools { namespace CppTools {
@@ -184,7 +183,7 @@ private:
// CTest integration // CTest integration
QString m_ctestPath; QString m_ctestPath;
QList<ProjectExplorer::TestCaseInfo> m_testNames; QList<ProjectExplorer::TestCaseInfo> m_testNames;
QFutureSynchronizer<QByteArray> m_futureSynchronizer; Utils::FutureSynchronizer m_futureSynchronizer;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -182,18 +182,6 @@ CppTypeHierarchyWidget::CppTypeHierarchyWidget()
m_synchronizer.setCancelOnWait(true); m_synchronizer.setCancelOnWait(true);
} }
void CppTypeHierarchyWidget::updateSynchronizer()
{
const QList<QFuture<void>> futures = m_synchronizer.futures();
m_synchronizer.clearFutures();
for (const QFuture<void> &future : futures) {
if (!future.isFinished())
m_synchronizer.addFuture(future);
}
}
void CppTypeHierarchyWidget::perform() void CppTypeHierarchyWidget::perform()
{ {
if (m_future.isRunning()) if (m_future.isRunning())
@@ -201,8 +189,6 @@ void CppTypeHierarchyWidget::perform()
m_showOldClass = false; m_showOldClass = false;
updateSynchronizer();
auto editor = qobject_cast<CppEditor *>(Core::EditorManager::currentEditor()); auto editor = qobject_cast<CppEditor *>(Core::EditorManager::currentEditor());
if (!editor) { if (!editor) {
showNoTypeHierarchyLabel(); showNoTypeHierarchyLabel();
@@ -219,7 +205,7 @@ void CppTypeHierarchyWidget::perform()
m_future = CppElementEvaluator::asyncExecute(widget); m_future = CppElementEvaluator::asyncExecute(widget);
m_futureWatcher.setFuture(QFuture<void>(m_future)); m_futureWatcher.setFuture(QFuture<void>(m_future));
m_synchronizer.addFuture(QFuture<void>(m_future)); m_synchronizer.addFuture(m_future);
Core::ProgressManager::addTask(m_future, tr("Evaluating Type Hierarchy"), "TypeHierarchy"); Core::ProgressManager::addTask(m_future, tr("Evaluating Type Hierarchy"), "TypeHierarchy");
} }
@@ -231,20 +217,18 @@ void CppTypeHierarchyWidget::performFromExpression(const QString &expression, co
m_showOldClass = true; m_showOldClass = true;
updateSynchronizer();
showProgress(); showProgress();
m_future = CppElementEvaluator::asyncExecute(expression, fileName); m_future = CppElementEvaluator::asyncExecute(expression, fileName);
m_futureWatcher.setFuture(QFuture<void>(m_future)); m_futureWatcher.setFuture(QFuture<void>(m_future));
m_synchronizer.addFuture(QFuture<void>(m_future)); m_synchronizer.addFuture(m_future);
Core::ProgressManager::addTask(m_future, tr("Evaluating Type Hierarchy"), "TypeHierarchy"); Core::ProgressManager::addTask(m_future, tr("Evaluating Type Hierarchy"), "TypeHierarchy");
} }
void CppTypeHierarchyWidget::displayHierarchy() void CppTypeHierarchyWidget::displayHierarchy()
{ {
updateSynchronizer(); m_synchronizer.flushFinishedFutures();
hideProgress(); hideProgress();
clearTypeHierarchy(); clearTypeHierarchy();

View File

@@ -26,10 +26,10 @@
#pragma once #pragma once
#include <coreplugin/inavigationwidgetfactory.h> #include <coreplugin/inavigationwidgetfactory.h>
#include <utils/futuresynchronizer.h>
#include <QFuture> #include <QFuture>
#include <QFutureWatcher> #include <QFutureWatcher>
#include <QFutureSynchronizer>
#include <QList> #include <QList>
#include <QSharedPointer> #include <QSharedPointer>
#include <QStackedWidget> #include <QStackedWidget>
@@ -94,7 +94,6 @@ private:
void clearTypeHierarchy(); void clearTypeHierarchy();
void onItemActivated(const QModelIndex &index); void onItemActivated(const QModelIndex &index);
void onItemDoubleClicked(const QModelIndex &index); void onItemDoubleClicked(const QModelIndex &index);
void updateSynchronizer();
CppEditorWidget *m_cppEditor = nullptr; CppEditorWidget *m_cppEditor = nullptr;
Utils::NavigationTreeView *m_treeView = nullptr; Utils::NavigationTreeView *m_treeView = nullptr;
@@ -106,7 +105,7 @@ private:
QLabel *m_infoLabel = nullptr; QLabel *m_infoLabel = nullptr;
QFuture<QSharedPointer<CppTools::CppElement>> m_future; QFuture<QSharedPointer<CppTools::CppElement>> m_future;
QFutureWatcher<void> m_futureWatcher; QFutureWatcher<void> m_futureWatcher;
QFutureSynchronizer<void> m_synchronizer; Utils::FutureSynchronizer m_synchronizer;
Utils::ProgressIndicator *m_progressIndicator = nullptr; Utils::ProgressIndicator *m_progressIndicator = nullptr;
QString m_oldClass; QString m_oldClass;
bool m_showOldClass = false; bool m_showOldClass = false;

View File

@@ -356,18 +356,6 @@ QFuture<void> BuiltinIndexingSupport::refreshSourceFiles(
params.sourceFiles = sourceFiles; params.sourceFiles = sourceFiles;
QFuture<void> result = Utils::runAsync(mgr->sharedThreadPool(), parse, params); QFuture<void> result = Utils::runAsync(mgr->sharedThreadPool(), parse, params);
if (m_synchronizer.futures().size() > 10) {
QList<QFuture<void> > futures = m_synchronizer.futures();
m_synchronizer.clearFutures();
foreach (const QFuture<void> &future, futures) {
if (!(future.isFinished() || future.isCanceled()))
m_synchronizer.addFuture(future);
}
}
m_synchronizer.addFuture(result); m_synchronizer.addFuture(result);
if (mode == CppModelManager::ForcedProgressNotification || sourceFiles.count() > 1) { if (mode == CppModelManager::ForcedProgressNotification || sourceFiles.count() > 1) {

View File

@@ -28,7 +28,7 @@
#include "cppindexingsupport.h" #include "cppindexingsupport.h"
#include "cppmodelmanager.h" #include "cppmodelmanager.h"
#include <QFutureSynchronizer> #include <utils/futuresynchronizer.h>
namespace CppTools { namespace CppTools {
namespace Internal { namespace Internal {
@@ -47,7 +47,7 @@ public:
static bool isFindErrorsIndexingActive(); static bool isFindErrorsIndexingActive();
private: private:
QFutureSynchronizer<void> m_synchronizer; Utils::FutureSynchronizer m_synchronizer;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -33,8 +33,8 @@
#include <vcsbase/vcsbaseclient.h> #include <vcsbase/vcsbaseclient.h>
#include <utils/fileutils.h> #include <utils/fileutils.h>
#include <utils/futuresynchronizer.h>
#include <QFutureSynchronizer>
#include <QObject> #include <QObject>
#include <QString> #include <QString>
#include <QStringList> #include <QStringList>
@@ -425,7 +425,7 @@ private:
QString m_diffCommit; QString m_diffCommit;
QStringList m_updatedSubmodules; QStringList m_updatedSubmodules;
bool m_disableEditor = false; bool m_disableEditor = false;
QFutureSynchronizer<void> m_synchronizer; // for commit updates Utils::FutureSynchronizer m_synchronizer; // for commit updates
}; };
class GitRemote : public Core::IVersionControl::RepoUrl class GitRemote : public Core::IVersionControl::RepoUrl

View File

@@ -62,14 +62,14 @@ CreateSimulatorDialog::CreateSimulatorDialog(QWidget *parent) :
}); });
m_futureSync.setCancelOnWait(true); m_futureSync.setCancelOnWait(true);
m_futureSync.addFuture(QFuture<void>(Utils::onResultReady(SimulatorControl::updateDeviceTypes(), this, m_futureSync.addFuture(Utils::onResultReady(SimulatorControl::updateDeviceTypes(), this,
&CreateSimulatorDialog::populateDeviceTypes))); &CreateSimulatorDialog::populateDeviceTypes));
QFuture<QList<RuntimeInfo>> runtimesfuture = SimulatorControl::updateRuntimes(); QFuture<QList<RuntimeInfo>> runtimesfuture = SimulatorControl::updateRuntimes();
Utils::onResultReady(runtimesfuture, this, [this](const QList<RuntimeInfo> &runtimes) { Utils::onResultReady(runtimesfuture, this, [this](const QList<RuntimeInfo> &runtimes) {
m_runtimes = runtimes; m_runtimes = runtimes;
}); });
m_futureSync.addFuture(QFuture<void>(runtimesfuture)); m_futureSync.addFuture(runtimesfuture);
populateRuntimes(DeviceTypeInfo()); populateRuntimes(DeviceTypeInfo());
} }

View File

@@ -26,7 +26,8 @@
#pragma once #pragma once
#include <QDialog> #include <QDialog>
#include <QFutureSynchronizer>
#include <utils/futuresynchronizer.h>
namespace Ios { namespace Ios {
namespace Internal { namespace Internal {
@@ -57,7 +58,7 @@ private:
void populateRuntimes(const DeviceTypeInfo &deviceType); void populateRuntimes(const DeviceTypeInfo &deviceType);
private: private:
QFutureSynchronizer<void> m_futureSync; Utils::FutureSynchronizer m_futureSync;
Ui::CreateSimulatorDialog *m_ui = nullptr; Ui::CreateSimulatorDialog *m_ui = nullptr;
SimulatorControl *m_simControl = nullptr; SimulatorControl *m_simControl = nullptr;
QList<RuntimeInfo> m_runtimes; QList<RuntimeInfo> m_runtimes;

View File

@@ -126,13 +126,12 @@ QModelIndex SimulatorInfoModel::parent(const QModelIndex &) const
void SimulatorInfoModel::requestSimulatorInfo() void SimulatorInfoModel::requestSimulatorInfo()
{ {
if (!m_fetchFuture.futures().isEmpty() && !m_fetchFuture.futures().at(0).isFinished()) m_fetchFuture.flushFinishedFutures();
if (!m_fetchFuture.isEmpty())
return; // Ignore the request if the last request is still pending. return; // Ignore the request if the last request is still pending.
m_fetchFuture.clearFutures(); m_fetchFuture.addFuture(Utils::onResultReady(SimulatorControl::updateAvailableSimulators(),
m_fetchFuture.addFuture(QFuture<void>(Utils::onResultReady( this, &SimulatorInfoModel::populateSimulators));
SimulatorControl::updateAvailableSimulators(),
this, &SimulatorInfoModel::populateSimulators)));
} }
void SimulatorInfoModel::populateSimulators(const SimulatorInfoList &simulatorList) void SimulatorInfoModel::populateSimulators(const SimulatorInfoList &simulatorList)

View File

@@ -27,8 +27,10 @@
#include "simulatorcontrol.h" #include "simulatorcontrol.h"
#include <utils/futuresynchronizer.h>
#include <QAbstractListModel> #include <QAbstractListModel>
#include <QFutureSynchronizer>
namespace Ios { namespace Ios {
namespace Internal { namespace Internal {
@@ -55,7 +57,7 @@ private:
void populateSimulators(const SimulatorInfoList &simulatorList); void populateSimulators(const SimulatorInfoList &simulatorList);
private: private:
QFutureSynchronizer<void> m_fetchFuture; Utils::FutureSynchronizer m_fetchFuture;
SimulatorInfoList m_simList; SimulatorInfoList m_simList;
}; };

View File

@@ -568,7 +568,7 @@ void SemanticHighlighter::rerun(const QmlJSTools::SemanticInfo &semanticInfo)
auto future = Utils::runAsync(QThread::LowestPriority, &SemanticHighlighter::run, auto future = Utils::runAsync(QThread::LowestPriority, &SemanticHighlighter::run,
this, semanticInfo); this, semanticInfo);
m_watcher.setFuture(future); m_watcher.setFuture(future);
m_futureSynchronizer.addFuture(QFuture<void>(future)); m_futureSynchronizer.addFuture(future);
} }
void SemanticHighlighter::cancel() void SemanticHighlighter::cancel()

View File

@@ -27,7 +27,7 @@
#include <qmljseditor/qmljseditor_global.h> #include <qmljseditor/qmljseditor_global.h>
#include <texteditor/semantichighlighter.h> #include <texteditor/semantichighlighter.h>
#include <QFutureSynchronizer> #include <utils/futuresynchronizer.h>
#include <QFutureWatcher> #include <QFutureWatcher>
#include <QTextLayout> #include <QTextLayout>
#include <QVector> #include <QVector>
@@ -90,7 +90,7 @@ private:
QHash<int, QTextCharFormat> m_formats; QHash<int, QTextCharFormat> m_formats;
QHash<int, QTextCharFormat> m_extraFormats; QHash<int, QTextCharFormat> m_extraFormats;
QVector<QTextLayout::FormatRange> m_diagnosticRanges; QVector<QTextLayout::FormatRange> m_diagnosticRanges;
QFutureSynchronizer<void> m_futureSynchronizer; Utils::FutureSynchronizer m_futureSynchronizer;
}; };
} // namespace QmlJSEditor } // namespace QmlJSEditor

View File

@@ -29,10 +29,10 @@
#include "clangiasyncjob.h" #include "clangiasyncjob.h"
#include <QDebug> #include <QDebug>
#include <QFutureSynchronizer>
#include <QLoggingCategory> #include <QLoggingCategory>
#include <utils/algorithm.h> #include <utils/algorithm.h>
#include <utils/futuresynchronizer.h>
#include <utils/qtcassert.h> #include <utils/qtcassert.h>
namespace ClangBackEnd { namespace ClangBackEnd {
@@ -63,7 +63,7 @@ Jobs::~Jobs()
foreach (IAsyncJob *asyncJob, m_running.keys()) foreach (IAsyncJob *asyncJob, m_running.keys())
asyncJob->preventFinalization(); asyncJob->preventFinalization();
QFutureSynchronizer<void> waitForFinishedJobs; Utils::FutureSynchronizer waitForFinishedJobs;
foreach (const RunningJob &runningJob, m_running.values()) foreach (const RunningJob &runningJob, m_running.values())
waitForFinishedJobs.addFuture(runningJob.future); waitForFinishedJobs.addFuture(runningJob.future);
@@ -114,7 +114,7 @@ JobRequests Jobs::stop()
queue().clear(); queue().clear();
// Wait until currently running jobs finish. // Wait until currently running jobs finish.
QFutureSynchronizer<void> waitForFinishedJobs; Utils::FutureSynchronizer waitForFinishedJobs;
foreach (const RunningJob &runningJob, m_running.values()) foreach (const RunningJob &runningJob, m_running.values())
waitForFinishedJobs.addFuture(runningJob.future); waitForFinishedJobs.addFuture(runningJob.future);