Commit 27425b62 authored by Eike Ziller's avatar Eike Ziller
Browse files

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's avatarOrgad Shaneh <orgads@gmail.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 3c8715f0
...@@ -520,6 +520,16 @@ void blockingMapReduce(QFutureInterface<ReduceResult> futureInterface, const Con ...@@ -520,6 +520,16 @@ void blockingMapReduce(QFutureInterface<ReduceResult> futureInterface, const Con
futureInterface.reportFinished(); 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 } // Internal
template <typename ReduceResult, typename Container, typename InitFunction, typename MapFunction, template <typename ReduceResult, typename Container, typename InitFunction, typename MapFunction,
...@@ -547,6 +557,15 @@ QFuture<ReduceResult> mapReduce(const Container &container, const InitFunction & ...@@ -547,6 +557,15 @@ QFuture<ReduceResult> mapReduce(const Container &container, const InitFunction &
return future; 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 } // Utils
#endif // RUNEXTENSIONS_H #endif // RUNEXTENSIONS_H
...@@ -51,8 +51,9 @@ QList<LocatorFilterEntry> BasicLocatorFilterTest::matchesFor(const QString &sear ...@@ -51,8 +51,9 @@ QList<LocatorFilterEntry> BasicLocatorFilterTest::matchesFor(const QString &sear
doBeforeLocatorRun(); doBeforeLocatorRun();
const QList<ILocatorFilter *> filters = QList<ILocatorFilter *>() << m_filter; const QList<ILocatorFilter *> filters = QList<ILocatorFilter *>() << m_filter;
m_filter->prepareSearch(searchText); m_filter->prepareSearch(searchText);
QFuture<LocatorFilterEntry> locatorSearch = QtConcurrent::run(Internal::runSearch, QFuture<LocatorFilterEntry> locatorSearch = Utils::runAsync<LocatorFilterEntry>(&Internal::runSearch,
filters, searchText); filters,
searchText);
locatorSearch.waitForFinished(); locatorSearch.waitForFinished();
doAfterLocatorRun(); doAfterLocatorRun();
return locatorSearch.results(); return locatorSearch.results();
......
...@@ -47,7 +47,7 @@ uint qHash(const LocatorFilterEntry &entry) ...@@ -47,7 +47,7 @@ uint qHash(const LocatorFilterEntry &entry)
} // namespace Core } // namespace Core
void Core::Internal::runSearch(QFutureInterface<Core::LocatorFilterEntry> &future, void Core::Internal::runSearch(QFutureInterface<Core::LocatorFilterEntry> &future,
QList<ILocatorFilter *> filters, QString searchText) const QList<ILocatorFilter *> &filters, const QString &searchText)
{ {
QSet<LocatorFilterEntry> alreadyAdded; QSet<LocatorFilterEntry> alreadyAdded;
const bool checkDuplicates = (filters.size() > 1); const bool checkDuplicates = (filters.size() > 1);
......
...@@ -37,8 +37,8 @@ namespace Core { ...@@ -37,8 +37,8 @@ namespace Core {
namespace Internal { namespace Internal {
void CORE_EXPORT runSearch(QFutureInterface<LocatorFilterEntry> &future, void CORE_EXPORT runSearch(QFutureInterface<LocatorFilterEntry> &future,
QList<ILocatorFilter *> filters, const QList<ILocatorFilter *> &filters,
QString searchText); const QString &searchText);
} // namespace Internal } // namespace Internal
} // namespace Core } // namespace Core
......
...@@ -524,7 +524,8 @@ void LocatorWidget::updateCompletionList(const QString &text) ...@@ -524,7 +524,8 @@ void LocatorWidget::updateCompletionList(const QString &text)
foreach (ILocatorFilter *filter, filters) foreach (ILocatorFilter *filter, filters)
filter->prepareSearch(searchText); 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); m_entriesWatcher->setFuture(future);
} }
......
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