From cc498ad4c14d907ceda4b5a30585423e4fb8d1de Mon Sep 17 00:00:00 2001 From: vng Date: Tue, 10 Apr 2012 20:24:26 +0300 Subject: [PATCH] Synchronization of CountryInfoGetter object in search::Engine. --- map/framework.cpp | 3 +++ search/search_engine.cpp | 18 +++++++++++++++--- search/search_engine.hpp | 8 +++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/map/framework.cpp b/map/framework.cpp index d405be2cc3..6ad58c66a2 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -668,6 +668,9 @@ void Framework::MemoryWarning() { // clearing caches on memory warning. m_model.ClearCaches(); + + GetSearchEngine()->ClearCaches(); + LOG(LINFO, ("MemoryWarning")); } diff --git a/search/search_engine.cpp b/search/search_engine.cpp index c1e26bc973..d9559cb305 100644 --- a/search/search_engine.cpp +++ b/search/search_engine.cpp @@ -265,23 +265,35 @@ void Engine::SearchAsync() } } -string Engine::GetCountryFile(m2::PointD const & pt) const +string Engine::GetCountryFile(m2::PointD const & pt) { + threads::MutexGuard searchGuard(m_searchMutex); + return m_pData->m_infoGetter.GetRegionFile(pt); } -string Engine::GetCountryCode(m2::PointD const & pt) const +string Engine::GetCountryCode(m2::PointD const & pt) { + threads::MutexGuard searchGuard(m_searchMutex); + storage::CountryInfo info; m_pData->m_infoGetter.GetRegionInfo(pt, info); return info.m_flag; } -string Engine::GetCountryName(m2::PointD const & pt) const +string Engine::GetCountryName(m2::PointD const & pt) { + threads::MutexGuard searchGuard(m_searchMutex); + storage::CountryInfo info; m_pData->m_infoGetter.GetRegionInfo(pt, info); return info.m_name; } +void Engine::ClearCaches() +{ + /// @todo Add m_pData->m_infoGetter clearing routine. + /// Now we have prereserved cache size. +} + } // namespace search diff --git a/search/search_engine.hpp b/search/search_engine.hpp index 298a4ae75f..a16f5d63e4 100644 --- a/search/search_engine.hpp +++ b/search/search_engine.hpp @@ -40,9 +40,11 @@ public: bool hasPt, double lat, double lon); void Search(SearchParams const & params, m2::RectD const & viewport); - string GetCountryFile(m2::PointD const & pt) const; - string GetCountryCode(m2::PointD const & pt) const; - string GetCountryName(m2::PointD const & pt) const; + string GetCountryFile(m2::PointD const & pt); + string GetCountryCode(m2::PointD const & pt); + string GetCountryName(m2::PointD const & pt); + + void ClearCaches(); private: static const int RESULTS_COUNT = 15;