Commit a30c1adc authored by Eike Ziller's avatar Eike Ziller
Browse files

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: default avatarMarco Benelli <marco.benelli@theqtcompany.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 677effda
......@@ -100,7 +100,6 @@ ModelManagerInterface::ModelManagerInterface(QObject *parent)
m_pluginDumper(new PluginDumper(this))
{
m_indexerEnabled = qgetenv("QTC_NO_CODE_INDEXER") != "1";
m_synchronizer.setCancelOnWait(true);
m_updateCppQmlTypesTimer = new QTimer(this);
m_updateCppQmlTypesTimer->setInterval(1000);
......@@ -302,6 +301,18 @@ void ModelManagerInterface::updateSourceFiles(const QStringList &files,
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,
bool emitDocumentOnDiskChanged)
{
......@@ -312,19 +323,8 @@ QFuture<void> ModelManagerInterface::refreshSourceFiles(const QStringList &sourc
workingCopyInternal(), sourceFiles,
this, Dialect(Dialect::Qml),
emitDocumentOnDiskChanged);
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);
cleanupFutures();
m_futures.append(result);
if (sourceFiles.count() > 1)
addTaskInternal(result, tr("Parsing QML Files"), Constants::TASK_INDEX);
......@@ -646,7 +646,7 @@ QList<ModelManagerInterface::ProjectInfo> ModelManagerInterface::allProjectInfos
bool ModelManagerInterface::isIdle() const
{
return m_synchronizer.futures().isEmpty();
return m_futures.isEmpty();
}
void ModelManagerInterface::emitDocumentChangedOnDisk(Document::Ptr doc)
......@@ -1099,19 +1099,8 @@ void ModelManagerInterface::maybeScan(const PathsAndLanguages &importPaths)
QFuture<void> result = QtConcurrent::run(&ModelManagerInterface::importScan,
workingCopyInternal(), pathToScan,
this, true, true);
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);
cleanupFutures();
m_futures.append(result);
addTaskInternal(result, tr("Scanning QML Imports"), Constants::TASK_IMPORT_SCAN);
}
......@@ -1485,8 +1474,9 @@ void ModelManagerInterface::setDefaultVContext(const ViewerContext &vContext)
void ModelManagerInterface::joinAllThreads()
{
foreach (QFuture<void> future, m_synchronizer.futures())
foreach (QFuture<void> future, m_futures)
future.waitForFinished();
m_futures.clear();
}
Document::Ptr ModelManagerInterface::ensuredGetDocumentForPath(const QString &filePath)
......
......@@ -36,7 +36,6 @@
#include <utils/environment.h>
#include <QFuture>
#include <QFutureSynchronizer>
#include <QHash>
#include <QObject>
#include <QPointer>
......@@ -250,6 +249,8 @@ protected:
void setDefaultProject(const ProjectInfo &pInfo, ProjectExplorer::Project *p);
private:
void cleanupFutures();
mutable QMutex m_mutex;
QmlJS::Snapshot m_validSnapshot;
QmlJS::Snapshot m_newestSnapshot;
......@@ -278,7 +279,7 @@ private:
PluginDumper *m_pluginDumper;
QFutureSynchronizer<void> m_synchronizer;
QList<QFuture<void>> m_futures;
bool m_indexerEnabled;
};
......
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