forked from qt-creator/qt-creator
QmlJSModelManager: Cleanup uses of QFuture
- Use simple list instead of QFutureSynchronizer (no feature of that was used) - Avoid duplicate code cleaning up the current list of running futures - Clean list of running futures after waiting for them all to finish Change-Id: Ia13ee25ab7835fc4f4970d23d20b16cfe6bf6dfb Reviewed-by: Marco Benelli <marco.benelli@theqtcompany.com> Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -100,7 +100,6 @@ ModelManagerInterface::ModelManagerInterface(QObject *parent)
|
|||||||
m_pluginDumper(new PluginDumper(this))
|
m_pluginDumper(new PluginDumper(this))
|
||||||
{
|
{
|
||||||
m_indexerEnabled = qgetenv("QTC_NO_CODE_INDEXER") != "1";
|
m_indexerEnabled = qgetenv("QTC_NO_CODE_INDEXER") != "1";
|
||||||
m_synchronizer.setCancelOnWait(true);
|
|
||||||
|
|
||||||
m_updateCppQmlTypesTimer = new QTimer(this);
|
m_updateCppQmlTypesTimer = new QTimer(this);
|
||||||
m_updateCppQmlTypesTimer->setInterval(1000);
|
m_updateCppQmlTypesTimer->setInterval(1000);
|
||||||
@@ -302,6 +301,18 @@ void ModelManagerInterface::updateSourceFiles(const QStringList &files,
|
|||||||
refreshSourceFiles(files, emitDocumentOnDiskChanged);
|
refreshSourceFiles(files, emitDocumentOnDiskChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelManagerInterface::cleanupFutures()
|
||||||
|
{
|
||||||
|
if (m_futures.size() > 10) {
|
||||||
|
QList<QFuture<void> > futures = m_futures;
|
||||||
|
m_futures.clear();
|
||||||
|
foreach (const QFuture<void> &future, futures) {
|
||||||
|
if (!(future.isFinished() || future.isCanceled()))
|
||||||
|
m_futures.append(future);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QFuture<void> ModelManagerInterface::refreshSourceFiles(const QStringList &sourceFiles,
|
QFuture<void> ModelManagerInterface::refreshSourceFiles(const QStringList &sourceFiles,
|
||||||
bool emitDocumentOnDiskChanged)
|
bool emitDocumentOnDiskChanged)
|
||||||
{
|
{
|
||||||
@@ -312,19 +323,8 @@ QFuture<void> ModelManagerInterface::refreshSourceFiles(const QStringList &sourc
|
|||||||
workingCopyInternal(), sourceFiles,
|
workingCopyInternal(), sourceFiles,
|
||||||
this, Dialect(Dialect::Qml),
|
this, Dialect(Dialect::Qml),
|
||||||
emitDocumentOnDiskChanged);
|
emitDocumentOnDiskChanged);
|
||||||
|
cleanupFutures();
|
||||||
if (m_synchronizer.futures().size() > 10) {
|
m_futures.append(result);
|
||||||
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);
|
|
||||||
|
|
||||||
if (sourceFiles.count() > 1)
|
if (sourceFiles.count() > 1)
|
||||||
addTaskInternal(result, tr("Parsing QML Files"), Constants::TASK_INDEX);
|
addTaskInternal(result, tr("Parsing QML Files"), Constants::TASK_INDEX);
|
||||||
@@ -646,7 +646,7 @@ QList<ModelManagerInterface::ProjectInfo> ModelManagerInterface::allProjectInfos
|
|||||||
|
|
||||||
bool ModelManagerInterface::isIdle() const
|
bool ModelManagerInterface::isIdle() const
|
||||||
{
|
{
|
||||||
return m_synchronizer.futures().isEmpty();
|
return m_futures.isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModelManagerInterface::emitDocumentChangedOnDisk(Document::Ptr doc)
|
void ModelManagerInterface::emitDocumentChangedOnDisk(Document::Ptr doc)
|
||||||
@@ -1099,19 +1099,8 @@ void ModelManagerInterface::maybeScan(const PathsAndLanguages &importPaths)
|
|||||||
QFuture<void> result = QtConcurrent::run(&ModelManagerInterface::importScan,
|
QFuture<void> result = QtConcurrent::run(&ModelManagerInterface::importScan,
|
||||||
workingCopyInternal(), pathToScan,
|
workingCopyInternal(), pathToScan,
|
||||||
this, true, true);
|
this, true, true);
|
||||||
|
cleanupFutures();
|
||||||
if (m_synchronizer.futures().size() > 10) {
|
m_futures.append(result);
|
||||||
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);
|
|
||||||
|
|
||||||
addTaskInternal(result, tr("Scanning QML Imports"), Constants::TASK_IMPORT_SCAN);
|
addTaskInternal(result, tr("Scanning QML Imports"), Constants::TASK_IMPORT_SCAN);
|
||||||
}
|
}
|
||||||
@@ -1485,8 +1474,9 @@ void ModelManagerInterface::setDefaultVContext(const ViewerContext &vContext)
|
|||||||
|
|
||||||
void ModelManagerInterface::joinAllThreads()
|
void ModelManagerInterface::joinAllThreads()
|
||||||
{
|
{
|
||||||
foreach (QFuture<void> future, m_synchronizer.futures())
|
foreach (QFuture<void> future, m_futures)
|
||||||
future.waitForFinished();
|
future.waitForFinished();
|
||||||
|
m_futures.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
Document::Ptr ModelManagerInterface::ensuredGetDocumentForPath(const QString &filePath)
|
Document::Ptr ModelManagerInterface::ensuredGetDocumentForPath(const QString &filePath)
|
||||||
|
@@ -36,7 +36,6 @@
|
|||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
|
|
||||||
#include <QFuture>
|
#include <QFuture>
|
||||||
#include <QFutureSynchronizer>
|
|
||||||
#include <QHash>
|
#include <QHash>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
@@ -250,6 +249,8 @@ protected:
|
|||||||
void setDefaultProject(const ProjectInfo &pInfo, ProjectExplorer::Project *p);
|
void setDefaultProject(const ProjectInfo &pInfo, ProjectExplorer::Project *p);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void cleanupFutures();
|
||||||
|
|
||||||
mutable QMutex m_mutex;
|
mutable QMutex m_mutex;
|
||||||
QmlJS::Snapshot m_validSnapshot;
|
QmlJS::Snapshot m_validSnapshot;
|
||||||
QmlJS::Snapshot m_newestSnapshot;
|
QmlJS::Snapshot m_newestSnapshot;
|
||||||
@@ -278,7 +279,7 @@ private:
|
|||||||
|
|
||||||
PluginDumper *m_pluginDumper;
|
PluginDumper *m_pluginDumper;
|
||||||
|
|
||||||
QFutureSynchronizer<void> m_synchronizer;
|
QList<QFuture<void>> m_futures;
|
||||||
bool m_indexerEnabled;
|
bool m_indexerEnabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user