diff --git a/libs/descriptions/loader.cpp b/libs/descriptions/loader.cpp index fa421763f..4fb11425e 100644 --- a/libs/descriptions/loader.cpp +++ b/libs/descriptions/loader.cpp @@ -2,8 +2,6 @@ #include "indexer/data_source.hpp" -#include "base/assert.hpp" - #include "defines.hpp" namespace descriptions @@ -20,17 +18,28 @@ std::string Loader::GetWikiDescription(FeatureID const & featureId, std::vector< if (!value.m_cont.IsExist(DESCRIPTIONS_FILE_TAG)) return {}; - EntryPtr entry; - { - std::lock_guard lock(m_mutex); - entry = m_deserializers.try_emplace(featureId.m_mwmId, std::make_shared()).first->second; - } + // No need to have separate mutexes for each MWM since there is no concurrent Wiki pages reading. + // Pros: lock is called once and a simple logic with OnMwmDeregistered synchronization. + /// @todo Consider removing mutex at all or make wiki loading async (PlacePage info). - ASSERT(entry, ()); + std::lock_guard lock(m_mutex); + Deserializer & deserializer = m_deserializers[featureId.m_mwmId]; auto readerPtr = value.m_cont.GetReader(DESCRIPTIONS_FILE_TAG); - - std::lock_guard lock(entry->m_mutex); - return entry->m_deserializer.Deserialize(*readerPtr.GetPtr(), featureId.m_index, langPriority); + return deserializer.Deserialize(*readerPtr.GetPtr(), featureId.m_index, langPriority); } + +void Loader::OnMwmDeregistered(platform::LocalCountryFile const & countryFile) +{ + std::lock_guard lock(m_mutex); + for (auto it = m_deserializers.begin(); it != m_deserializers.end(); ++it) + { + if (it->first.IsDeregistered(countryFile)) + { + m_deserializers.erase(it); + break; + } + } +} + } // namespace descriptions diff --git a/libs/descriptions/loader.hpp b/libs/descriptions/loader.hpp index 8355ad6e1..45c5c204e 100644 --- a/libs/descriptions/loader.hpp +++ b/libs/descriptions/loader.hpp @@ -5,9 +5,7 @@ #include "indexer/feature_decl.hpp" #include "indexer/mwm_set.hpp" -#include #include -#include #include #include #include @@ -23,18 +21,11 @@ public: explicit Loader(DataSource const & dataSource) : m_dataSource(dataSource) {} std::string GetWikiDescription(FeatureID const & featureId, std::vector const & langPriority); + void OnMwmDeregistered(platform::LocalCountryFile const & countryFile); private: - struct Entry - { - std::mutex m_mutex; - Deserializer m_deserializer; - }; - - using EntryPtr = std::shared_ptr; - DataSource const & m_dataSource; - std::map m_deserializers; + std::map m_deserializers; std::mutex m_mutex; }; } // namespace descriptions diff --git a/libs/map/framework.cpp b/libs/map/framework.cpp index 823b1b53d..92d37542e 100644 --- a/libs/map/framework.cpp +++ b/libs/map/framework.cpp @@ -444,6 +444,7 @@ void Framework::OnMapDeregistered(platform::LocalCountryFile const & localFile) m_transitManager.OnMwmDeregistered(localFile); m_isolinesManager.OnMwmDeregistered(localFile); m_trafficManager.OnMwmDeregistered(localFile); + m_descriptionsLoader->OnMwmDeregistered(localFile); m_storage.DeleteCustomCountryVersion(localFile); };