forked from organicmaps/organicmaps
[search] Avoid many search threads waiting in search mutex.
This commit is contained in:
parent
4154928d44
commit
ea00efe391
2 changed files with 16 additions and 2 deletions
|
@ -129,7 +129,6 @@ void Engine::Search(SearchParams const & params, m2::RectD const & viewport)
|
|||
|
||||
{
|
||||
threads::MutexGuard guard(m_updateMutex);
|
||||
|
||||
m_params = params;
|
||||
m_viewport = viewport;
|
||||
}
|
||||
|
@ -153,12 +152,25 @@ void Engine::SetViewportAsync(m2::RectD const & viewport, m2::RectD const & near
|
|||
|
||||
void Engine::SearchAsync()
|
||||
{
|
||||
{
|
||||
// Avoid many threads waiting in search mutex. One is enough.
|
||||
threads::MutexGuard readyGuard(m_readyMutex);
|
||||
if (m_readyThread)
|
||||
return;
|
||||
m_readyThread = true;
|
||||
}
|
||||
|
||||
// First of all - cancel previous query.
|
||||
m_pQuery->DoCancel();
|
||||
|
||||
// Enter to run new search.
|
||||
threads::MutexGuard searchGuard(m_searchMutex);
|
||||
|
||||
{
|
||||
threads::MutexGuard readyGuard(m_readyMutex);
|
||||
m_readyThread = false;
|
||||
}
|
||||
|
||||
// Get current search params.
|
||||
SearchParams params;
|
||||
m2::RectD arrRects[2];
|
||||
|
|
|
@ -47,7 +47,9 @@ private:
|
|||
void SetViewportAsync(m2::RectD const & viewport, m2::RectD const & nearby);
|
||||
void SearchAsync();
|
||||
|
||||
threads::Mutex m_searchMutex, m_updateMutex;
|
||||
threads::Mutex m_searchMutex, m_updateMutex, m_readyMutex;
|
||||
|
||||
volatile bool m_readyThread;
|
||||
|
||||
SearchParams m_params;
|
||||
m2::RectD m_viewport;
|
||||
|
|
Loading…
Add table
Reference in a new issue