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:
@@ -25,8 +25,8 @@
|
||||
#include <texteditor/basefilefind.h>
|
||||
|
||||
#include <utils/algorithm.h>
|
||||
#include <utils/asynctask.h>
|
||||
#include <utils/qtcassert.h>
|
||||
#include <utils/runextensions.h>
|
||||
#include <utils/textfileformat.h>
|
||||
|
||||
#include <QtConcurrentMap>
|
||||
@@ -220,7 +220,7 @@ class ProcessFile
|
||||
const CPlusPlus::Snapshot snapshot;
|
||||
CPlusPlus::Document::Ptr symbolDocument;
|
||||
CPlusPlus::Symbol *symbol;
|
||||
QFutureInterface<CPlusPlus::Usage> *future;
|
||||
QPromise<CPlusPlus::Usage> *m_promise;
|
||||
const bool categorize;
|
||||
|
||||
public:
|
||||
@@ -232,22 +232,21 @@ public:
|
||||
const CPlusPlus::Snapshot snapshot,
|
||||
CPlusPlus::Document::Ptr symbolDocument,
|
||||
CPlusPlus::Symbol *symbol,
|
||||
QFutureInterface<CPlusPlus::Usage> *future,
|
||||
QPromise<CPlusPlus::Usage> *promise,
|
||||
bool categorize)
|
||||
: workingCopy(workingCopy),
|
||||
snapshot(snapshot),
|
||||
symbolDocument(symbolDocument),
|
||||
symbol(symbol),
|
||||
future(future),
|
||||
m_promise(promise),
|
||||
categorize(categorize)
|
||||
{ }
|
||||
|
||||
QList<CPlusPlus::Usage> operator()(const Utils::FilePath &filePath)
|
||||
{
|
||||
QList<CPlusPlus::Usage> usages;
|
||||
if (future->isPaused())
|
||||
future->waitForResume();
|
||||
if (future->isCanceled())
|
||||
m_promise->suspendIfRequested();
|
||||
if (m_promise->isCanceled())
|
||||
return usages;
|
||||
const CPlusPlus::Identifier *symbolId = symbol->identifier();
|
||||
|
||||
@@ -277,25 +276,24 @@ public:
|
||||
usages = process.usages();
|
||||
}
|
||||
|
||||
if (future->isPaused())
|
||||
future->waitForResume();
|
||||
m_promise->suspendIfRequested();
|
||||
return usages;
|
||||
}
|
||||
};
|
||||
|
||||
class UpdateUI
|
||||
{
|
||||
QFutureInterface<CPlusPlus::Usage> *future;
|
||||
QPromise<CPlusPlus::Usage> *m_promise;
|
||||
|
||||
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)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static void find_helper(QFutureInterface<CPlusPlus::Usage> &future,
|
||||
static void find_helper(QPromise<CPlusPlus::Usage> &promise,
|
||||
const WorkingCopy workingCopy,
|
||||
const CPlusPlus::LookupContext &context,
|
||||
CPlusPlus::Symbol *symbol,
|
||||
@@ -355,16 +353,16 @@ static void find_helper(QFutureInterface<CPlusPlus::Usage> &future,
|
||||
}
|
||||
files = Utils::filteredUnique(files);
|
||||
|
||||
future.setProgressRange(0, files.size());
|
||||
promise.setProgressRange(0, files.size());
|
||||
|
||||
ProcessFile process(workingCopy, snapshot, context.thisDocument(), symbol, &future, categorize);
|
||||
UpdateUI reduce(&future);
|
||||
ProcessFile process(workingCopy, snapshot, context.thisDocument(), symbol, &promise, categorize);
|
||||
UpdateUI reduce(&promise);
|
||||
// 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.
|
||||
QThreadPool::globalInstance()->releaseThread();
|
||||
QtConcurrent::blockingMappedReduced<QList<CPlusPlus::Usage> > (files, process, reduce);
|
||||
QThreadPool::globalInstance()->reserveThread();
|
||||
future.setProgressValue(files.size());
|
||||
promise.setProgressValue(files.size());
|
||||
}
|
||||
|
||||
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);
|
||||
const WorkingCopy workingCopy = m_modelManager->workingCopy();
|
||||
QFuture<CPlusPlus::Usage> result;
|
||||
result = Utils::runAsync(m_modelManager->sharedThreadPool(), find_helper,
|
||||
result = Utils::asyncRun(m_modelManager->sharedThreadPool(), find_helper,
|
||||
workingCopy, context, symbol, categorize);
|
||||
createWatcher(result, search);
|
||||
|
||||
@@ -625,7 +623,7 @@ class FindMacroUsesInFile
|
||||
const WorkingCopy workingCopy;
|
||||
const CPlusPlus::Snapshot snapshot;
|
||||
const CPlusPlus::Macro ¯o;
|
||||
QFutureInterface<CPlusPlus::Usage> *future;
|
||||
QPromise<CPlusPlus::Usage> *m_promise;
|
||||
|
||||
public:
|
||||
// needed by QtConcurrent
|
||||
@@ -635,8 +633,8 @@ public:
|
||||
FindMacroUsesInFile(const WorkingCopy &workingCopy,
|
||||
const CPlusPlus::Snapshot snapshot,
|
||||
const CPlusPlus::Macro ¯o,
|
||||
QFutureInterface<CPlusPlus::Usage> *future)
|
||||
: workingCopy(workingCopy), snapshot(snapshot), macro(macro), future(future)
|
||||
QPromise<CPlusPlus::Usage> *promise)
|
||||
: workingCopy(workingCopy), snapshot(snapshot), macro(macro), m_promise(promise)
|
||||
{ }
|
||||
|
||||
QList<CPlusPlus::Usage> operator()(const Utils::FilePath &fileName)
|
||||
@@ -646,9 +644,8 @@ public:
|
||||
QByteArray source;
|
||||
|
||||
restart_search:
|
||||
if (future->isPaused())
|
||||
future->waitForResume();
|
||||
if (future->isCanceled())
|
||||
m_promise->suspendIfRequested();
|
||||
if (m_promise->isCanceled())
|
||||
return usages;
|
||||
|
||||
usages.clear();
|
||||
@@ -676,8 +673,7 @@ restart_search:
|
||||
}
|
||||
}
|
||||
|
||||
if (future->isPaused())
|
||||
future->waitForResume();
|
||||
m_promise->suspendIfRequested();
|
||||
return usages;
|
||||
}
|
||||
|
||||
@@ -706,7 +702,7 @@ restart_search:
|
||||
|
||||
} // end of anonymous namespace
|
||||
|
||||
static void findMacroUses_helper(QFutureInterface<CPlusPlus::Usage> &future,
|
||||
static void findMacroUses_helper(QPromise<CPlusPlus::Usage> &promise,
|
||||
const WorkingCopy workingCopy,
|
||||
const CPlusPlus::Snapshot snapshot,
|
||||
const CPlusPlus::Macro macro)
|
||||
@@ -715,15 +711,15 @@ static void findMacroUses_helper(QFutureInterface<CPlusPlus::Usage> &future,
|
||||
FilePaths files{sourceFile};
|
||||
files = Utils::filteredUnique(files + snapshot.filesDependingOn(sourceFile));
|
||||
|
||||
future.setProgressRange(0, files.size());
|
||||
FindMacroUsesInFile process(workingCopy, snapshot, macro, &future);
|
||||
UpdateUI reduce(&future);
|
||||
promise.setProgressRange(0, files.size());
|
||||
FindMacroUsesInFile process(workingCopy, snapshot, macro, &promise);
|
||||
UpdateUI reduce(&promise);
|
||||
// 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.
|
||||
QThreadPool::globalInstance()->releaseThread();
|
||||
QtConcurrent::blockingMappedReduced<QList<CPlusPlus::Usage> > (files, process, reduce);
|
||||
QThreadPool::globalInstance()->reserveThread();
|
||||
future.setProgressValue(files.size());
|
||||
promise.setProgressValue(files.size());
|
||||
}
|
||||
|
||||
void CppFindReferences::findMacroUses(const CPlusPlus::Macro ¯o)
|
||||
@@ -773,7 +769,7 @@ void CppFindReferences::findMacroUses(const CPlusPlus::Macro ¯o, const QStri
|
||||
}
|
||||
|
||||
QFuture<CPlusPlus::Usage> result;
|
||||
result = Utils::runAsync(m_modelManager->sharedThreadPool(), findMacroUses_helper,
|
||||
result = Utils::asyncRun(m_modelManager->sharedThreadPool(), findMacroUses_helper,
|
||||
workingCopy, snapshot, macro);
|
||||
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::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));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user