forked from qt-creator/qt-creator
Locator: Avoid use of QtConcurrent
QtConcurrent limits resource usage to a global number of simultaneous threads. That means that if some QtConcurrent based algorithm currently grabs all threads, any other use of QtConcurrent blocks, which is not what we want. Use the new threading methods of C++11 instead, but still use QFuture(Interface) manually for status reporting. Task-number: QTCREATORBUG-14640 Change-Id: I8fecb43b5235da92c0d239e7dd5f2c108ab32ebf Reviewed-by: Orgad Shaneh <orgads@gmail.com> Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com>
This commit is contained in:
@@ -520,6 +520,16 @@ void blockingMapReduce(QFutureInterface<ReduceResult> futureInterface, const Con
|
||||
futureInterface.reportFinished();
|
||||
}
|
||||
|
||||
template <typename ResultType, typename Function, typename... Args>
|
||||
void runAsyncImpl(QFutureInterface<ResultType> futureInterface, const Function &function, const Args&... args)
|
||||
{
|
||||
futureInterface.reportStarted();
|
||||
function(futureInterface, args...);
|
||||
if (futureInterface.isPaused())
|
||||
futureInterface.waitForResume();
|
||||
futureInterface.reportFinished();
|
||||
}
|
||||
|
||||
} // Internal
|
||||
|
||||
template <typename ReduceResult, typename Container, typename InitFunction, typename MapFunction,
|
||||
@@ -547,6 +557,15 @@ QFuture<ReduceResult> mapReduce(const Container &container, const InitFunction &
|
||||
return future;
|
||||
}
|
||||
|
||||
template <typename ResultType, typename Function, typename... Args>
|
||||
QFuture<ResultType> runAsync(Function &&function, Args&&... args)
|
||||
{
|
||||
QFutureInterface<ResultType> futureInterface;
|
||||
std::thread(Internal::runAsyncImpl<ResultType,Function,Args...>, futureInterface,
|
||||
std::forward<Function>(function), std::forward<Args>(args)...).detach();
|
||||
return futureInterface.future();
|
||||
}
|
||||
|
||||
} // Utils
|
||||
|
||||
#endif // RUNEXTENSIONS_H
|
||||
|
@@ -51,8 +51,9 @@ QList<LocatorFilterEntry> BasicLocatorFilterTest::matchesFor(const QString &sear
|
||||
doBeforeLocatorRun();
|
||||
const QList<ILocatorFilter *> filters = QList<ILocatorFilter *>() << m_filter;
|
||||
m_filter->prepareSearch(searchText);
|
||||
QFuture<LocatorFilterEntry> locatorSearch = QtConcurrent::run(Internal::runSearch,
|
||||
filters, searchText);
|
||||
QFuture<LocatorFilterEntry> locatorSearch = Utils::runAsync<LocatorFilterEntry>(&Internal::runSearch,
|
||||
filters,
|
||||
searchText);
|
||||
locatorSearch.waitForFinished();
|
||||
doAfterLocatorRun();
|
||||
return locatorSearch.results();
|
||||
|
@@ -47,7 +47,7 @@ uint qHash(const LocatorFilterEntry &entry)
|
||||
} // namespace Core
|
||||
|
||||
void Core::Internal::runSearch(QFutureInterface<Core::LocatorFilterEntry> &future,
|
||||
QList<ILocatorFilter *> filters, QString searchText)
|
||||
const QList<ILocatorFilter *> &filters, const QString &searchText)
|
||||
{
|
||||
QSet<LocatorFilterEntry> alreadyAdded;
|
||||
const bool checkDuplicates = (filters.size() > 1);
|
||||
|
@@ -37,8 +37,8 @@ namespace Core {
|
||||
namespace Internal {
|
||||
|
||||
void CORE_EXPORT runSearch(QFutureInterface<LocatorFilterEntry> &future,
|
||||
QList<ILocatorFilter *> filters,
|
||||
QString searchText);
|
||||
const QList<ILocatorFilter *> &filters,
|
||||
const QString &searchText);
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace Core
|
||||
|
@@ -524,7 +524,8 @@ void LocatorWidget::updateCompletionList(const QString &text)
|
||||
|
||||
foreach (ILocatorFilter *filter, filters)
|
||||
filter->prepareSearch(searchText);
|
||||
QFuture<LocatorFilterEntry> future = QtConcurrent::run(runSearch, filters, searchText);
|
||||
QFuture<LocatorFilterEntry> future = Utils::runAsync<LocatorFilterEntry>(&runSearch, filters,
|
||||
QString(searchText));
|
||||
m_entriesWatcher->setFuture(future);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user