forked from qt-creator/qt-creator
CppEditor: Use QtConcurrent invocation for async run
Change-Id: Ibbac7f7788fe966c0dd846d68b7d17c43acadb0e Reviewed-by: Christian Kandeler <christian.kandeler@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
@@ -59,15 +59,15 @@ void BaseEditorDocumentParser::setConfiguration(const Configuration &configurati
|
|||||||
|
|
||||||
void BaseEditorDocumentParser::update(const UpdateParams &updateParams)
|
void BaseEditorDocumentParser::update(const UpdateParams &updateParams)
|
||||||
{
|
{
|
||||||
QFutureInterface<void> dummy;
|
QPromise<void> dummy;
|
||||||
update(dummy, updateParams);
|
update(dummy, updateParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseEditorDocumentParser::update(const QFutureInterface<void> &future,
|
void BaseEditorDocumentParser::update(const QPromise<void> &promise,
|
||||||
const UpdateParams &updateParams)
|
const UpdateParams &updateParams)
|
||||||
{
|
{
|
||||||
QMutexLocker locker(&m_updateIsRunning);
|
QMutexLocker locker(&m_updateIsRunning);
|
||||||
updateImpl(future, updateParams);
|
updateImpl(promise, updateParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseEditorDocumentParser::State BaseEditorDocumentParser::state() const
|
BaseEditorDocumentParser::State BaseEditorDocumentParser::state() const
|
||||||
|
|||||||
@@ -6,14 +6,17 @@
|
|||||||
#include "cppeditor_global.h"
|
#include "cppeditor_global.h"
|
||||||
#include "cpptoolsreuse.h"
|
#include "cpptoolsreuse.h"
|
||||||
#include "cppworkingcopy.h"
|
#include "cppworkingcopy.h"
|
||||||
#include "projectpart.h"
|
|
||||||
|
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
|
|
||||||
#include <QFutureInterface>
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
|
|
||||||
|
QT_BEGIN_NAMESPACE
|
||||||
|
template <typename T>
|
||||||
|
class QPromise;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace ProjectExplorer { class Project; }
|
namespace ProjectExplorer { class Project; }
|
||||||
|
|
||||||
namespace CppEditor {
|
namespace CppEditor {
|
||||||
@@ -66,7 +69,7 @@ public:
|
|||||||
void setConfiguration(const Configuration &configuration);
|
void setConfiguration(const Configuration &configuration);
|
||||||
|
|
||||||
void update(const UpdateParams &updateParams);
|
void update(const UpdateParams &updateParams);
|
||||||
void update(const QFutureInterface<void> &future, const UpdateParams &updateParams);
|
void update(const QPromise<void> &promise, const UpdateParams &updateParams);
|
||||||
|
|
||||||
ProjectPartInfo projectPartInfo() const;
|
ProjectPartInfo projectPartInfo() const;
|
||||||
|
|
||||||
@@ -91,7 +94,7 @@ protected:
|
|||||||
mutable QMutex m_stateAndConfigurationMutex;
|
mutable QMutex m_stateAndConfigurationMutex;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual void updateImpl(const QFutureInterface<void> &future,
|
virtual void updateImpl(const QPromise<void> &promise,
|
||||||
const UpdateParams &updateParams) = 0;
|
const UpdateParams &updateParams) = 0;
|
||||||
|
|
||||||
const Utils::FilePath m_filePath;
|
const Utils::FilePath m_filePath;
|
||||||
|
|||||||
@@ -59,20 +59,20 @@ void BaseEditorDocumentProcessor::setParserConfig(
|
|||||||
parser()->setConfiguration(config);
|
parser()->setConfiguration(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseEditorDocumentProcessor::runParser(QFutureInterface<void> &future,
|
void BaseEditorDocumentProcessor::runParser(QPromise<void> &promise,
|
||||||
BaseEditorDocumentParser::Ptr parser,
|
BaseEditorDocumentParser::Ptr parser,
|
||||||
BaseEditorDocumentParser::UpdateParams updateParams)
|
BaseEditorDocumentParser::UpdateParams updateParams)
|
||||||
{
|
{
|
||||||
future.setProgressRange(0, 1);
|
promise.setProgressRange(0, 1);
|
||||||
if (future.isCanceled()) {
|
if (promise.isCanceled()) {
|
||||||
future.setProgressValue(1);
|
promise.setProgressValue(1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
parser->update(future, updateParams);
|
parser->update(promise, updateParams);
|
||||||
CppModelManager::instance()->finishedRefreshingSourceFiles({parser->filePath().toString()});
|
CppModelManager::instance()->finishedRefreshingSourceFiles({parser->filePath().toString()});
|
||||||
|
|
||||||
future.setProgressValue(1);
|
promise.setProgressValue(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace CppEditor
|
} // namespace CppEditor
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ signals:
|
|||||||
void semanticInfoUpdated(const SemanticInfo semanticInfo); // TODO: Remove me
|
void semanticInfoUpdated(const SemanticInfo semanticInfo); // TODO: Remove me
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void runParser(QFutureInterface<void> &future,
|
static void runParser(QPromise<void> &promise,
|
||||||
BaseEditorDocumentParser::Ptr parser,
|
BaseEditorDocumentParser::Ptr parser,
|
||||||
BaseEditorDocumentParser::UpdateParams updateParams);
|
BaseEditorDocumentParser::UpdateParams updateParams);
|
||||||
|
|
||||||
|
|||||||
@@ -14,9 +14,9 @@
|
|||||||
#include <cplusplus/Macro.h>
|
#include <cplusplus/Macro.h>
|
||||||
#include <cplusplus/TranslationUnit.h>
|
#include <cplusplus/TranslationUnit.h>
|
||||||
|
|
||||||
#include <utils/textutils.h>
|
#include <utils/asynctask.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/runextensions.h>
|
#include <utils/textutils.h>
|
||||||
|
|
||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
|
|
||||||
@@ -322,7 +322,7 @@ QFuture<CursorInfo> BuiltinCursorInfo::run(const CursorInfoParams &cursorInfoPar
|
|||||||
QString expression;
|
QString expression;
|
||||||
Scope *scope = canonicalSymbol.getScopeAndExpression(textCursor, &expression);
|
Scope *scope = canonicalSymbol.getScopeAndExpression(textCursor, &expression);
|
||||||
|
|
||||||
return Utils::runAsync(&FindUses::find, document, snapshot, line, column, scope, expression);
|
return Utils::asyncRun(&FindUses::find, document, snapshot, line, column, scope, expression);
|
||||||
}
|
}
|
||||||
|
|
||||||
SemanticInfo::LocalUseMap
|
SemanticInfo::LocalUseMap
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ BuiltinEditorDocumentParser::BuiltinEditorDocumentParser(const FilePath &filePat
|
|||||||
qRegisterMetaType<CPlusPlus::Snapshot>("CPlusPlus::Snapshot");
|
qRegisterMetaType<CPlusPlus::Snapshot>("CPlusPlus::Snapshot");
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &future,
|
void BuiltinEditorDocumentParser::updateImpl(const QPromise<void> &promise,
|
||||||
const UpdateParams &updateParams)
|
const UpdateParams &updateParams)
|
||||||
{
|
{
|
||||||
if (filePath().isEmpty())
|
if (filePath().isEmpty())
|
||||||
@@ -180,7 +180,7 @@ void BuiltinEditorDocumentParser::updateImpl(const QFutureInterface<void> &futur
|
|||||||
doc->releaseSourceAndAST();
|
doc->releaseSourceAndAST();
|
||||||
});
|
});
|
||||||
sourceProcessor.setFileSizeLimitInMb(m_fileSizeLimitInMb);
|
sourceProcessor.setFileSizeLimitInMb(m_fileSizeLimitInMb);
|
||||||
sourceProcessor.setCancelChecker([future]() { return future.isCanceled(); });
|
sourceProcessor.setCancelChecker([&promise] { return promise.isCanceled(); });
|
||||||
|
|
||||||
Snapshot globalSnapshot = modelManager->snapshot();
|
Snapshot globalSnapshot = modelManager->snapshot();
|
||||||
globalSnapshot.remove(filePath());
|
globalSnapshot.remove(filePath());
|
||||||
|
|||||||
@@ -34,8 +34,7 @@ public:
|
|||||||
static Ptr get(const Utils::FilePath &filePath);
|
static Ptr get(const Utils::FilePath &filePath);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void updateImpl(const QFutureInterface<void> &future,
|
void updateImpl(const QPromise<void> &promise, const UpdateParams &updateParams) override;
|
||||||
const UpdateParams &updateParams) override;
|
|
||||||
void addFileAndDependencies(CPlusPlus::Snapshot *snapshot,
|
void addFileAndDependencies(CPlusPlus::Snapshot *snapshot,
|
||||||
QSet<Utils::FilePath> *toRemove,
|
QSet<Utils::FilePath> *toRemove,
|
||||||
const Utils::FilePath &fileName) const;
|
const Utils::FilePath &fileName) const;
|
||||||
|
|||||||
@@ -18,9 +18,9 @@
|
|||||||
#include <cplusplus/CppDocument.h>
|
#include <cplusplus/CppDocument.h>
|
||||||
#include <cplusplus/SimpleLexer.h>
|
#include <cplusplus/SimpleLexer.h>
|
||||||
|
|
||||||
#include <utils/textutils.h>
|
#include <utils/asynctask.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/runextensions.h>
|
#include <utils/textutils.h>
|
||||||
|
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
@@ -180,10 +180,8 @@ BuiltinEditorDocumentProcessor::~BuiltinEditorDocumentProcessor()
|
|||||||
void BuiltinEditorDocumentProcessor::runImpl(
|
void BuiltinEditorDocumentProcessor::runImpl(
|
||||||
const BaseEditorDocumentParser::UpdateParams &updateParams)
|
const BaseEditorDocumentParser::UpdateParams &updateParams)
|
||||||
{
|
{
|
||||||
m_parserFuture = Utils::runAsync(CppModelManager::instance()->sharedThreadPool(),
|
m_parserFuture = Utils::asyncRun(CppModelManager::instance()->sharedThreadPool(),
|
||||||
runParser,
|
runParser, parser(), updateParams);
|
||||||
parser(),
|
|
||||||
updateParams);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseEditorDocumentParser::Ptr BuiltinEditorDocumentProcessor::parser()
|
BaseEditorDocumentParser::Ptr BuiltinEditorDocumentProcessor::parser()
|
||||||
|
|||||||
@@ -25,8 +25,8 @@
|
|||||||
#include <texteditor/basefilefind.h>
|
#include <texteditor/basefilefind.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/asynctask.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/runextensions.h>
|
|
||||||
#include <utils/textfileformat.h>
|
#include <utils/textfileformat.h>
|
||||||
|
|
||||||
#include <QtConcurrentMap>
|
#include <QtConcurrentMap>
|
||||||
@@ -220,7 +220,7 @@ class ProcessFile
|
|||||||
const CPlusPlus::Snapshot snapshot;
|
const CPlusPlus::Snapshot snapshot;
|
||||||
CPlusPlus::Document::Ptr symbolDocument;
|
CPlusPlus::Document::Ptr symbolDocument;
|
||||||
CPlusPlus::Symbol *symbol;
|
CPlusPlus::Symbol *symbol;
|
||||||
QFutureInterface<CPlusPlus::Usage> *future;
|
QPromise<CPlusPlus::Usage> *m_promise;
|
||||||
const bool categorize;
|
const bool categorize;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -232,22 +232,21 @@ public:
|
|||||||
const CPlusPlus::Snapshot snapshot,
|
const CPlusPlus::Snapshot snapshot,
|
||||||
CPlusPlus::Document::Ptr symbolDocument,
|
CPlusPlus::Document::Ptr symbolDocument,
|
||||||
CPlusPlus::Symbol *symbol,
|
CPlusPlus::Symbol *symbol,
|
||||||
QFutureInterface<CPlusPlus::Usage> *future,
|
QPromise<CPlusPlus::Usage> *promise,
|
||||||
bool categorize)
|
bool categorize)
|
||||||
: workingCopy(workingCopy),
|
: workingCopy(workingCopy),
|
||||||
snapshot(snapshot),
|
snapshot(snapshot),
|
||||||
symbolDocument(symbolDocument),
|
symbolDocument(symbolDocument),
|
||||||
symbol(symbol),
|
symbol(symbol),
|
||||||
future(future),
|
m_promise(promise),
|
||||||
categorize(categorize)
|
categorize(categorize)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
QList<CPlusPlus::Usage> operator()(const Utils::FilePath &filePath)
|
QList<CPlusPlus::Usage> operator()(const Utils::FilePath &filePath)
|
||||||
{
|
{
|
||||||
QList<CPlusPlus::Usage> usages;
|
QList<CPlusPlus::Usage> usages;
|
||||||
if (future->isPaused())
|
m_promise->suspendIfRequested();
|
||||||
future->waitForResume();
|
if (m_promise->isCanceled())
|
||||||
if (future->isCanceled())
|
|
||||||
return usages;
|
return usages;
|
||||||
const CPlusPlus::Identifier *symbolId = symbol->identifier();
|
const CPlusPlus::Identifier *symbolId = symbol->identifier();
|
||||||
|
|
||||||
@@ -277,25 +276,24 @@ public:
|
|||||||
usages = process.usages();
|
usages = process.usages();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (future->isPaused())
|
m_promise->suspendIfRequested();
|
||||||
future->waitForResume();
|
|
||||||
return usages;
|
return usages;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
class UpdateUI
|
class UpdateUI
|
||||||
{
|
{
|
||||||
QFutureInterface<CPlusPlus::Usage> *future;
|
QPromise<CPlusPlus::Usage> *m_promise;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit UpdateUI(QFutureInterface<CPlusPlus::Usage> *future): future(future) {}
|
explicit UpdateUI(QPromise<CPlusPlus::Usage> *promise): m_promise(promise) {}
|
||||||
|
|
||||||
void operator()(QList<CPlusPlus::Usage> &, const QList<CPlusPlus::Usage> &usages)
|
void operator()(QList<CPlusPlus::Usage> &, const QList<CPlusPlus::Usage> &usages)
|
||||||
{
|
{
|
||||||
for (const CPlusPlus::Usage &u : usages)
|
for (const CPlusPlus::Usage &u : usages)
|
||||||
future->reportResult(u);
|
m_promise->addResult(u);
|
||||||
|
|
||||||
future->setProgressValue(future->progressValue() + 1);
|
m_promise->setProgressValue(m_promise->future().progressValue() + 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -321,7 +319,7 @@ QList<int> CppFindReferences::references(CPlusPlus::Symbol *symbol,
|
|||||||
return references;
|
return references;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void find_helper(QFutureInterface<CPlusPlus::Usage> &future,
|
static void find_helper(QPromise<CPlusPlus::Usage> &promise,
|
||||||
const WorkingCopy workingCopy,
|
const WorkingCopy workingCopy,
|
||||||
const CPlusPlus::LookupContext &context,
|
const CPlusPlus::LookupContext &context,
|
||||||
CPlusPlus::Symbol *symbol,
|
CPlusPlus::Symbol *symbol,
|
||||||
@@ -355,16 +353,16 @@ static void find_helper(QFutureInterface<CPlusPlus::Usage> &future,
|
|||||||
}
|
}
|
||||||
files = Utils::filteredUnique(files);
|
files = Utils::filteredUnique(files);
|
||||||
|
|
||||||
future.setProgressRange(0, files.size());
|
promise.setProgressRange(0, files.size());
|
||||||
|
|
||||||
ProcessFile process(workingCopy, snapshot, context.thisDocument(), symbol, &future, categorize);
|
ProcessFile process(workingCopy, snapshot, context.thisDocument(), symbol, &promise, categorize);
|
||||||
UpdateUI reduce(&future);
|
UpdateUI reduce(&promise);
|
||||||
// This thread waits for blockingMappedReduced to finish, so reduce the pool's used thread count
|
// This thread waits for blockingMappedReduced to finish, so reduce the pool's used thread count
|
||||||
// so the blockingMappedReduced can use one more thread, and increase it again afterwards.
|
// so the blockingMappedReduced can use one more thread, and increase it again afterwards.
|
||||||
QThreadPool::globalInstance()->releaseThread();
|
QThreadPool::globalInstance()->releaseThread();
|
||||||
QtConcurrent::blockingMappedReduced<QList<CPlusPlus::Usage> > (files, process, reduce);
|
QtConcurrent::blockingMappedReduced<QList<CPlusPlus::Usage> > (files, process, reduce);
|
||||||
QThreadPool::globalInstance()->reserveThread();
|
QThreadPool::globalInstance()->reserveThread();
|
||||||
future.setProgressValue(files.size());
|
promise.setProgressValue(files.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol,
|
void CppFindReferences::findUsages(CPlusPlus::Symbol *symbol,
|
||||||
@@ -439,7 +437,7 @@ void CppFindReferences::findAll_helper(SearchResult *search, CPlusPlus::Symbol *
|
|||||||
SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
|
SearchResultWindow::instance()->popup(IOutputPane::ModeSwitch | IOutputPane::WithFocus);
|
||||||
const WorkingCopy workingCopy = m_modelManager->workingCopy();
|
const WorkingCopy workingCopy = m_modelManager->workingCopy();
|
||||||
QFuture<CPlusPlus::Usage> result;
|
QFuture<CPlusPlus::Usage> result;
|
||||||
result = Utils::runAsync(m_modelManager->sharedThreadPool(), find_helper,
|
result = Utils::asyncRun(m_modelManager->sharedThreadPool(), find_helper,
|
||||||
workingCopy, context, symbol, categorize);
|
workingCopy, context, symbol, categorize);
|
||||||
createWatcher(result, search);
|
createWatcher(result, search);
|
||||||
|
|
||||||
@@ -625,7 +623,7 @@ class FindMacroUsesInFile
|
|||||||
const WorkingCopy workingCopy;
|
const WorkingCopy workingCopy;
|
||||||
const CPlusPlus::Snapshot snapshot;
|
const CPlusPlus::Snapshot snapshot;
|
||||||
const CPlusPlus::Macro ¯o;
|
const CPlusPlus::Macro ¯o;
|
||||||
QFutureInterface<CPlusPlus::Usage> *future;
|
QPromise<CPlusPlus::Usage> *m_promise;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// needed by QtConcurrent
|
// needed by QtConcurrent
|
||||||
@@ -635,8 +633,8 @@ public:
|
|||||||
FindMacroUsesInFile(const WorkingCopy &workingCopy,
|
FindMacroUsesInFile(const WorkingCopy &workingCopy,
|
||||||
const CPlusPlus::Snapshot snapshot,
|
const CPlusPlus::Snapshot snapshot,
|
||||||
const CPlusPlus::Macro ¯o,
|
const CPlusPlus::Macro ¯o,
|
||||||
QFutureInterface<CPlusPlus::Usage> *future)
|
QPromise<CPlusPlus::Usage> *promise)
|
||||||
: workingCopy(workingCopy), snapshot(snapshot), macro(macro), future(future)
|
: workingCopy(workingCopy), snapshot(snapshot), macro(macro), m_promise(promise)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
QList<CPlusPlus::Usage> operator()(const Utils::FilePath &fileName)
|
QList<CPlusPlus::Usage> operator()(const Utils::FilePath &fileName)
|
||||||
@@ -646,9 +644,8 @@ public:
|
|||||||
QByteArray source;
|
QByteArray source;
|
||||||
|
|
||||||
restart_search:
|
restart_search:
|
||||||
if (future->isPaused())
|
m_promise->suspendIfRequested();
|
||||||
future->waitForResume();
|
if (m_promise->isCanceled())
|
||||||
if (future->isCanceled())
|
|
||||||
return usages;
|
return usages;
|
||||||
|
|
||||||
usages.clear();
|
usages.clear();
|
||||||
@@ -676,8 +673,7 @@ restart_search:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (future->isPaused())
|
m_promise->suspendIfRequested();
|
||||||
future->waitForResume();
|
|
||||||
return usages;
|
return usages;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -706,7 +702,7 @@ restart_search:
|
|||||||
|
|
||||||
} // end of anonymous namespace
|
} // end of anonymous namespace
|
||||||
|
|
||||||
static void findMacroUses_helper(QFutureInterface<CPlusPlus::Usage> &future,
|
static void findMacroUses_helper(QPromise<CPlusPlus::Usage> &promise,
|
||||||
const WorkingCopy workingCopy,
|
const WorkingCopy workingCopy,
|
||||||
const CPlusPlus::Snapshot snapshot,
|
const CPlusPlus::Snapshot snapshot,
|
||||||
const CPlusPlus::Macro macro)
|
const CPlusPlus::Macro macro)
|
||||||
@@ -715,15 +711,15 @@ static void findMacroUses_helper(QFutureInterface<CPlusPlus::Usage> &future,
|
|||||||
FilePaths files{sourceFile};
|
FilePaths files{sourceFile};
|
||||||
files = Utils::filteredUnique(files + snapshot.filesDependingOn(sourceFile));
|
files = Utils::filteredUnique(files + snapshot.filesDependingOn(sourceFile));
|
||||||
|
|
||||||
future.setProgressRange(0, files.size());
|
promise.setProgressRange(0, files.size());
|
||||||
FindMacroUsesInFile process(workingCopy, snapshot, macro, &future);
|
FindMacroUsesInFile process(workingCopy, snapshot, macro, &promise);
|
||||||
UpdateUI reduce(&future);
|
UpdateUI reduce(&promise);
|
||||||
// This thread waits for blockingMappedReduced to finish, so reduce the pool's used thread count
|
// This thread waits for blockingMappedReduced to finish, so reduce the pool's used thread count
|
||||||
// so the blockingMappedReduced can use one more thread, and increase it again afterwards.
|
// so the blockingMappedReduced can use one more thread, and increase it again afterwards.
|
||||||
QThreadPool::globalInstance()->releaseThread();
|
QThreadPool::globalInstance()->releaseThread();
|
||||||
QtConcurrent::blockingMappedReduced<QList<CPlusPlus::Usage> > (files, process, reduce);
|
QtConcurrent::blockingMappedReduced<QList<CPlusPlus::Usage> > (files, process, reduce);
|
||||||
QThreadPool::globalInstance()->reserveThread();
|
QThreadPool::globalInstance()->reserveThread();
|
||||||
future.setProgressValue(files.size());
|
promise.setProgressValue(files.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CppFindReferences::findMacroUses(const CPlusPlus::Macro ¯o)
|
void CppFindReferences::findMacroUses(const CPlusPlus::Macro ¯o)
|
||||||
@@ -773,7 +769,7 @@ void CppFindReferences::findMacroUses(const CPlusPlus::Macro ¯o, const QStri
|
|||||||
}
|
}
|
||||||
|
|
||||||
QFuture<CPlusPlus::Usage> result;
|
QFuture<CPlusPlus::Usage> result;
|
||||||
result = Utils::runAsync(m_modelManager->sharedThreadPool(), findMacroUses_helper,
|
result = Utils::asyncRun(m_modelManager->sharedThreadPool(), findMacroUses_helper,
|
||||||
workingCopy, snapshot, macro);
|
workingCopy, snapshot, macro);
|
||||||
createWatcher(result, search);
|
createWatcher(result, search);
|
||||||
|
|
||||||
@@ -834,7 +830,7 @@ void CppFindReferences::checkUnused(Core::SearchResult *search, const Link &link
|
|||||||
});
|
});
|
||||||
connect(search, &SearchResult::canceled, watcher, [watcher] { watcher->cancel(); });
|
connect(search, &SearchResult::canceled, watcher, [watcher] { watcher->cancel(); });
|
||||||
connect(search, &SearchResult::destroyed, watcher, [watcher] { watcher->cancel(); });
|
connect(search, &SearchResult::destroyed, watcher, [watcher] { watcher->cancel(); });
|
||||||
watcher->setFuture(Utils::runAsync(m_modelManager->sharedThreadPool(), find_helper,
|
watcher->setFuture(Utils::asyncRun(m_modelManager->sharedThreadPool(), find_helper,
|
||||||
m_modelManager->workingCopy(), context, symbol, true));
|
m_modelManager->workingCopy(), context, symbol, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,9 +21,9 @@
|
|||||||
#include <cplusplus/Overview.h>
|
#include <cplusplus/Overview.h>
|
||||||
#include <cplusplus/TypeOfExpression.h>
|
#include <cplusplus/TypeOfExpression.h>
|
||||||
|
|
||||||
|
#include <utils/asynctask.h>
|
||||||
#include <utils/proxyaction.h>
|
#include <utils/proxyaction.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/runextensions.h>
|
|
||||||
#include <utils/tooltip/tooltip.h>
|
#include <utils/tooltip/tooltip.h>
|
||||||
|
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
@@ -232,7 +232,7 @@ void FunctionDeclDefLinkFinder::startFindLinkAt(
|
|||||||
// handle the rest in a thread
|
// handle the rest in a thread
|
||||||
m_watcher.reset(new QFutureWatcher<QSharedPointer<FunctionDeclDefLink> >());
|
m_watcher.reset(new QFutureWatcher<QSharedPointer<FunctionDeclDefLink> >());
|
||||||
connect(m_watcher.data(), &QFutureWatcherBase::finished, this, &FunctionDeclDefLinkFinder::onFutureDone);
|
connect(m_watcher.data(), &QFutureWatcherBase::finished, this, &FunctionDeclDefLinkFinder::onFutureDone);
|
||||||
m_watcher->setFuture(Utils::runAsync(findLinkHelper, result, refactoringChanges));
|
m_watcher->setFuture(Utils::asyncRun(findLinkHelper, result, refactoringChanges));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FunctionDeclDefLink::isValid() const
|
bool FunctionDeclDefLink::isValid() const
|
||||||
|
|||||||
@@ -15,8 +15,8 @@
|
|||||||
|
|
||||||
#include <cplusplus/LookupContext.h>
|
#include <cplusplus/LookupContext.h>
|
||||||
|
|
||||||
|
#include <utils/asynctask.h>
|
||||||
#include <utils/filepath.h>
|
#include <utils/filepath.h>
|
||||||
#include <utils/runextensions.h>
|
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
#include <utils/temporarydirectory.h>
|
#include <utils/temporarydirectory.h>
|
||||||
|
|
||||||
@@ -116,8 +116,7 @@ void classifyFiles(const QSet<QString> &files, QStringList *headers, QStringList
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void indexFindErrors(QFutureInterface<void> &indexingFuture,
|
void indexFindErrors(QPromise<void> &promise, const ParseParams params)
|
||||||
const ParseParams params)
|
|
||||||
{
|
{
|
||||||
QStringList sources, headers;
|
QStringList sources, headers;
|
||||||
classifyFiles(params.sourceFiles, &headers, &sources);
|
classifyFiles(params.sourceFiles, &headers, &sources);
|
||||||
@@ -130,7 +129,7 @@ void indexFindErrors(QFutureInterface<void> &indexingFuture,
|
|||||||
timer.start();
|
timer.start();
|
||||||
|
|
||||||
for (int i = 0, end = files.size(); i < end ; ++i) {
|
for (int i = 0, end = files.size(); i < end ; ++i) {
|
||||||
if (indexingFuture.isCanceled())
|
if (promise.isCanceled())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
const QString file = files.at(i);
|
const QString file = files.at(i);
|
||||||
@@ -153,15 +152,14 @@ void indexFindErrors(QFutureInterface<void> &indexingFuture,
|
|||||||
|
|
||||||
document->releaseSourceAndAST();
|
document->releaseSourceAndAST();
|
||||||
|
|
||||||
indexingFuture.setProgressValue(i + 1);
|
promise.setProgressValue(i + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
const QString elapsedTime = Utils::formatElapsedTime(timer.elapsed());
|
const QString elapsedTime = Utils::formatElapsedTime(timer.elapsed());
|
||||||
qDebug("FindErrorsIndexing: %s", qPrintable(elapsedTime));
|
qDebug("FindErrorsIndexing: %s", qPrintable(elapsedTime));
|
||||||
}
|
}
|
||||||
|
|
||||||
void index(QFutureInterface<void> &indexingFuture,
|
void index(QPromise<void> &promise, const ParseParams params)
|
||||||
const ParseParams params)
|
|
||||||
{
|
{
|
||||||
QScopedPointer<Internal::CppSourceProcessor> sourceProcessor(CppModelManager::createSourceProcessor());
|
QScopedPointer<Internal::CppSourceProcessor> sourceProcessor(CppModelManager::createSourceProcessor());
|
||||||
sourceProcessor->setFileSizeLimitInMb(params.indexerFileSizeLimitInMb);
|
sourceProcessor->setFileSizeLimitInMb(params.indexerFileSizeLimitInMb);
|
||||||
@@ -190,7 +188,7 @@ void index(QFutureInterface<void> &indexingFuture,
|
|||||||
|
|
||||||
qCDebug(indexerLog) << "About to index" << files.size() << "files.";
|
qCDebug(indexerLog) << "About to index" << files.size() << "files.";
|
||||||
for (int i = 0; i < files.size(); ++i) {
|
for (int i = 0; i < files.size(); ++i) {
|
||||||
if (indexingFuture.isCanceled())
|
if (promise.isCanceled())
|
||||||
break;
|
break;
|
||||||
|
|
||||||
const QString fileName = files.at(i);
|
const QString fileName = files.at(i);
|
||||||
@@ -216,7 +214,7 @@ void index(QFutureInterface<void> &indexingFuture,
|
|||||||
sourceProcessor->setHeaderPaths(headerPaths);
|
sourceProcessor->setHeaderPaths(headerPaths);
|
||||||
sourceProcessor->run(FilePath::fromString(fileName));
|
sourceProcessor->run(FilePath::fromString(fileName));
|
||||||
|
|
||||||
indexingFuture.setProgressValue(files.size() - sourceProcessor->todo().size());
|
promise.setProgressValue(files.size() - sourceProcessor->todo().size());
|
||||||
|
|
||||||
if (isSourceFile)
|
if (isSourceFile)
|
||||||
sourceProcessor->resetEnvironment();
|
sourceProcessor->resetEnvironment();
|
||||||
@@ -224,29 +222,29 @@ void index(QFutureInterface<void> &indexingFuture,
|
|||||||
qCDebug(indexerLog) << "Indexing finished.";
|
qCDebug(indexerLog) << "Indexing finished.";
|
||||||
}
|
}
|
||||||
|
|
||||||
void parse(QFutureInterface<void> &indexingFuture, const ParseParams params)
|
void parse(QPromise<void> &promise, const ParseParams params)
|
||||||
{
|
{
|
||||||
const QSet<QString> &files = params.sourceFiles;
|
const QSet<QString> &files = params.sourceFiles;
|
||||||
if (files.isEmpty())
|
if (files.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
indexingFuture.setProgressRange(0, files.size());
|
promise.setProgressRange(0, files.size());
|
||||||
|
|
||||||
if (CppIndexingSupport::isFindErrorsIndexingActive())
|
if (CppIndexingSupport::isFindErrorsIndexingActive())
|
||||||
indexFindErrors(indexingFuture, params);
|
indexFindErrors(promise, params);
|
||||||
else
|
else
|
||||||
index(indexingFuture, params);
|
index(promise, params);
|
||||||
|
|
||||||
indexingFuture.setProgressValue(files.size());
|
promise.setProgressValue(files.size());
|
||||||
CppModelManager::instance()->finishedRefreshingSourceFiles(files);
|
CppModelManager::instance()->finishedRefreshingSourceFiles(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // anonymous namespace
|
} // anonymous namespace
|
||||||
|
|
||||||
void SymbolSearcher::runSearch(QFutureInterface<Core::SearchResultItem> &future)
|
void SymbolSearcher::runSearch(QPromise<Core::SearchResultItem> &promise)
|
||||||
{
|
{
|
||||||
future.setProgressRange(0, m_snapshot.size());
|
promise.setProgressRange(0, m_snapshot.size());
|
||||||
future.setProgressValue(0);
|
promise.setProgressValue(0);
|
||||||
int progress = 0;
|
int progress = 0;
|
||||||
|
|
||||||
SearchSymbols search;
|
SearchSymbols search;
|
||||||
@@ -262,9 +260,8 @@ void SymbolSearcher::runSearch(QFutureInterface<Core::SearchResultItem> &future)
|
|||||||
: QRegularExpression::CaseInsensitiveOption));
|
: QRegularExpression::CaseInsensitiveOption));
|
||||||
matcher.optimize();
|
matcher.optimize();
|
||||||
while (it != m_snapshot.end()) {
|
while (it != m_snapshot.end()) {
|
||||||
if (future.isPaused())
|
promise.suspendIfRequested();
|
||||||
future.waitForResume();
|
if (promise.isCanceled())
|
||||||
if (future.isCanceled())
|
|
||||||
break;
|
break;
|
||||||
if (m_fileNames.isEmpty() || m_fileNames.contains(it.value()->filePath().path())) {
|
if (m_fileNames.isEmpty() || m_fileNames.contains(it.value()->filePath().path())) {
|
||||||
QVector<Core::SearchResultItem> resultItems;
|
QVector<Core::SearchResultItem> resultItems;
|
||||||
@@ -291,15 +288,14 @@ void SymbolSearcher::runSearch(QFutureInterface<Core::SearchResultItem> &future)
|
|||||||
return IndexItem::Recurse;
|
return IndexItem::Recurse;
|
||||||
};
|
};
|
||||||
search(it.value())->visitAllChildren(filter);
|
search(it.value())->visitAllChildren(filter);
|
||||||
if (!resultItems.isEmpty())
|
for (const Core::SearchResultItem &item : std::as_const(resultItems))
|
||||||
future.reportResults(resultItems);
|
promise.addResult(item);
|
||||||
}
|
}
|
||||||
++it;
|
++it;
|
||||||
++progress;
|
++progress;
|
||||||
future.setProgressValue(progress);
|
promise.setProgressValue(progress);
|
||||||
}
|
}
|
||||||
if (future.isPaused())
|
promise.suspendIfRequested();
|
||||||
future.waitForResume();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CppIndexingSupport::CppIndexingSupport()
|
CppIndexingSupport::CppIndexingSupport()
|
||||||
@@ -325,7 +321,7 @@ QFuture<void> CppIndexingSupport::refreshSourceFiles(const QSet<QString> &source
|
|||||||
params.workingCopy = mgr->workingCopy();
|
params.workingCopy = mgr->workingCopy();
|
||||||
params.sourceFiles = sourceFiles;
|
params.sourceFiles = sourceFiles;
|
||||||
|
|
||||||
QFuture<void> result = Utils::runAsync(mgr->sharedThreadPool(), parse, params);
|
QFuture<void> result = Utils::asyncRun(mgr->sharedThreadPool(), parse, params);
|
||||||
m_synchronizer.addFuture(result);
|
m_synchronizer.addFuture(result);
|
||||||
|
|
||||||
if (mode == CppModelManager::ForcedProgressNotification || sourceFiles.count() > 1) {
|
if (mode == CppModelManager::ForcedProgressNotification || sourceFiles.count() > 1) {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
SymbolSearcher(const SymbolSearcher::Parameters ¶meters, const QSet<QString> &fileNames);
|
SymbolSearcher(const SymbolSearcher::Parameters ¶meters, const QSet<QString> &fileNames);
|
||||||
void runSearch(QFutureInterface<Core::SearchResultItem> &future);
|
void runSearch(QPromise<Core::SearchResultItem> &promise);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const CPlusPlus::Snapshot m_snapshot;
|
const CPlusPlus::Snapshot m_snapshot;
|
||||||
|
|||||||
@@ -3,11 +3,10 @@
|
|||||||
|
|
||||||
#include "cppsemanticinfoupdater.h"
|
#include "cppsemanticinfoupdater.h"
|
||||||
|
|
||||||
#include "cpplocalsymbols.h"
|
|
||||||
#include "cppmodelmanager.h"
|
#include "cppmodelmanager.h"
|
||||||
|
|
||||||
|
#include <utils/asynctask.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/runextensions.h>
|
|
||||||
|
|
||||||
#include <cplusplus/Control.h>
|
#include <cplusplus/Control.h>
|
||||||
#include <cplusplus/CppDocument.h>
|
#include <cplusplus/CppDocument.h>
|
||||||
@@ -29,11 +28,11 @@ public:
|
|||||||
class FuturizedTopLevelDeclarationProcessor: public TopLevelDeclarationProcessor
|
class FuturizedTopLevelDeclarationProcessor: public TopLevelDeclarationProcessor
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit FuturizedTopLevelDeclarationProcessor(QFutureInterface<void> &future): m_future(future) {}
|
explicit FuturizedTopLevelDeclarationProcessor(QPromise<void> &promise): m_promise(promise) {}
|
||||||
bool processDeclaration(DeclarationAST *) override { return !isCanceled(); }
|
bool processDeclaration(DeclarationAST *) override { return !isCanceled(); }
|
||||||
bool isCanceled() { return m_future.isCanceled(); }
|
bool isCanceled() { return m_promise.isCanceled(); }
|
||||||
private:
|
private:
|
||||||
QFutureInterface<void> m_future;
|
QPromise<void> &m_promise;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -49,7 +48,7 @@ public:
|
|||||||
|
|
||||||
bool reuseCurrentSemanticInfo(const SemanticInfo::Source &source, bool emitSignalWhenFinished);
|
bool reuseCurrentSemanticInfo(const SemanticInfo::Source &source, bool emitSignalWhenFinished);
|
||||||
|
|
||||||
void update_helper(QFutureInterface<void> &future, const SemanticInfo::Source &source);
|
void update_helper(QPromise<void> &promise, const SemanticInfo::Source &source);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SemanticInfoUpdater *q;
|
SemanticInfoUpdater *q;
|
||||||
@@ -136,10 +135,10 @@ bool SemanticInfoUpdaterPrivate::reuseCurrentSemanticInfo(const SemanticInfo::So
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SemanticInfoUpdaterPrivate::update_helper(QFutureInterface<void> &future,
|
void SemanticInfoUpdaterPrivate::update_helper(QPromise<void> &promise,
|
||||||
const SemanticInfo::Source &source)
|
const SemanticInfo::Source &source)
|
||||||
{
|
{
|
||||||
FuturizedTopLevelDeclarationProcessor processor(future);
|
FuturizedTopLevelDeclarationProcessor processor(promise);
|
||||||
update(source, true, &processor);
|
update(source, true, &processor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +178,7 @@ void SemanticInfoUpdater::updateDetached(const SemanticInfo::Source &source)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
d->m_future = Utils::runAsync(CppModelManager::instance()->sharedThreadPool(),
|
d->m_future = Utils::asyncRun(CppModelManager::instance()->sharedThreadPool(),
|
||||||
&SemanticInfoUpdaterPrivate::update_helper, d.data(), source);
|
&SemanticInfoUpdaterPrivate::update_helper, d.data(), source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,13 +4,13 @@
|
|||||||
#include "symbolsearcher_test.h"
|
#include "symbolsearcher_test.h"
|
||||||
|
|
||||||
#include "cppindexingsupport.h"
|
#include "cppindexingsupport.h"
|
||||||
#include "cppmodelmanager.h"
|
|
||||||
#include "cpptoolstestcase.h"
|
#include "cpptoolstestcase.h"
|
||||||
#include "searchsymbols.h"
|
#include "searchsymbols.h"
|
||||||
|
|
||||||
#include <coreplugin/testdatadir.h>
|
#include <coreplugin/testdatadir.h>
|
||||||
#include <coreplugin/find/searchresultwindow.h>
|
#include <coreplugin/find/searchresultwindow.h>
|
||||||
#include <utils/runextensions.h>
|
|
||||||
|
#include <utils/asynctask.h>
|
||||||
|
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ public:
|
|||||||
const QScopedPointer<SymbolSearcher> symbolSearcher(
|
const QScopedPointer<SymbolSearcher> symbolSearcher(
|
||||||
new SymbolSearcher(searchParameters, QSet<QString>{testFile}));
|
new SymbolSearcher(searchParameters, QSet<QString>{testFile}));
|
||||||
QFuture<Core::SearchResultItem> search
|
QFuture<Core::SearchResultItem> search
|
||||||
= Utils::runAsync(&SymbolSearcher::runSearch, symbolSearcher.data());
|
= Utils::asyncRun(&SymbolSearcher::runSearch, symbolSearcher.data());
|
||||||
search.waitForFinished();
|
search.waitForFinished();
|
||||||
ResultDataList results = ResultData::fromSearchResultList(search.results());
|
ResultDataList results = ResultData::fromSearchResultList(search.results());
|
||||||
QCOMPARE(results, expectedResults);
|
QCOMPARE(results, expectedResults);
|
||||||
|
|||||||
@@ -18,13 +18,13 @@
|
|||||||
#include <projectexplorer/projectmanager.h>
|
#include <projectexplorer/projectmanager.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/runextensions.h>
|
#include <utils/asynctask.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QSet>
|
#include <QButtonGroup>
|
||||||
#include <QGridLayout>
|
#include <QGridLayout>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QButtonGroup>
|
#include <QSet>
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
@@ -121,7 +121,7 @@ void SymbolsFindFilter::startSearch(SearchResult *search)
|
|||||||
SymbolSearcher *symbolSearcher = new SymbolSearcher(parameters, projectFileNames);
|
SymbolSearcher *symbolSearcher = new SymbolSearcher(parameters, projectFileNames);
|
||||||
connect(watcher, &QFutureWatcherBase::finished,
|
connect(watcher, &QFutureWatcherBase::finished,
|
||||||
symbolSearcher, &QObject::deleteLater);
|
symbolSearcher, &QObject::deleteLater);
|
||||||
watcher->setFuture(Utils::runAsync(m_manager->sharedThreadPool(),
|
watcher->setFuture(Utils::asyncRun(m_manager->sharedThreadPool(),
|
||||||
&SymbolSearcher::runSearch, symbolSearcher));
|
&SymbolSearcher::runSearch, symbolSearcher));
|
||||||
FutureProgress *progress = ProgressManager::addTask(watcher->future(), Tr::tr("Searching for Symbol"),
|
FutureProgress *progress = ProgressManager::addTask(watcher->future(), Tr::tr("Searching for Symbol"),
|
||||||
Core::Constants::TASK_SEARCH);
|
Core::Constants::TASK_SEARCH);
|
||||||
|
|||||||
Reference in New Issue
Block a user