Fixed races.

Signed-off-by: Viktor Govako <viktor.govako@gmail.com>
This commit is contained in:
Viktor Govako
2022-06-26 17:33:57 +03:00
committed by zyphlar
parent fca2a64a80
commit b4cc6b140b
2 changed files with 6 additions and 5 deletions

View File

@@ -700,9 +700,8 @@ void Generator::InitCountryInfoGetter(std::string const & dataDir)
GetPlatform().SetResourceDir(dataDir); GetPlatform().SetResourceDir(dataDir);
m_infoGetter = storage::CountryInfoReader::CreateCountryInfoReader(GetPlatform()); m_infoReader = storage::CountryInfoReader::CreateCountryInfoReader(GetPlatform());
CHECK(m_infoGetter, ()); CHECK(m_infoReader, ());
m_infoReader = static_cast<storage::CountryInfoReader *>(m_infoGetter.get());
} }
void Generator::InitProfiles(std::string const & isolinesProfilesFileName, void Generator::InitProfiles(std::string const & isolinesProfilesFileName,
@@ -767,6 +766,8 @@ void Generator::GetCountryRegions(storage::CountryId const & countryId, m2::Rect
} }
CHECK_LESS(id, m_infoReader->GetCountries().size(), ()); CHECK_LESS(id, m_infoReader->GetCountries().size(), ());
/// @todo Refactor using Memory[Mapped] reader for countries.
std::lock_guard guard(m_infoMutex);
m_infoReader->LoadRegionsFromDisk(id, countryRegions); m_infoReader->LoadRegionsFromDisk(id, countryRegions);
} }
} // namespace topography_generator } // namespace topography_generator

View File

@@ -91,8 +91,8 @@ private:
ProfileToTileIsolinesParams m_profileToTileParams; ProfileToTileIsolinesParams m_profileToTileParams;
ProfileToIsolinesPackingParams m_profileToPackingParams; ProfileToIsolinesPackingParams m_profileToPackingParams;
std::unique_ptr<storage::CountryInfoGetter> m_infoGetter; std::mutex m_infoMutex;
storage::CountryInfoReader * m_infoReader = nullptr; std::unique_ptr<storage::CountryInfoReader> m_infoReader;
// They can't be negative, it is done to avoid compiler warnings. // They can't be negative, it is done to avoid compiler warnings.
long m_threadsCount; long m_threadsCount;