mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-23 06:33:42 +00:00
Synchronize map updates with traffic manager
Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
@@ -443,13 +443,13 @@ void Framework::OnCountryFileDownloaded(storage::CountryId const &,
|
||||
m2::RectD rect = mercator::Bounds::FullRect();
|
||||
|
||||
if (localFile && localFile->OnDisk(MapFileType::Map))
|
||||
{
|
||||
m_trafficManager.RunSynchronized([this, localFile, &rect](){
|
||||
auto const res = RegisterMap(*localFile);
|
||||
MwmSet::MwmId const & id = res.first;
|
||||
if (id.IsAlive())
|
||||
rect = id.GetInfo()->m_bordersRect;
|
||||
m_trafficManager.Invalidate(id);
|
||||
}
|
||||
});
|
||||
|
||||
m_transitManager.Invalidate();
|
||||
m_isolinesManager.Invalidate();
|
||||
|
||||
@@ -301,9 +301,6 @@ void TrafficManager::Invalidate(MwmSet::MwmId const & mwmId)
|
||||
auto const mwmRect = mwmId.GetInfo()->m_bordersRect; // m2::RectD
|
||||
traffxml::TraffFeed invalidated;
|
||||
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
|
||||
for (auto it = m_messageCache.begin(); it != m_messageCache.end(); )
|
||||
{
|
||||
if (!it->second.m_location)
|
||||
@@ -349,7 +346,6 @@ void TrafficManager::Invalidate(MwmSet::MwmId const & mwmId)
|
||||
m_condition.notify_one();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TrafficManager::UpdateActiveMwms(m2::RectD const & rect,
|
||||
std::vector<MwmSet::MwmId> & lastMwmsByRect,
|
||||
|
||||
@@ -224,6 +224,9 @@ public:
|
||||
* for these locations are discarded and decoded again, ensuring they are based on the new MWM.
|
||||
* The TraFF messages themselves remain unchanged.
|
||||
*
|
||||
* This method must either be called from a lambda function passed to `RunSynchronized()`,
|
||||
* or the caller must explicitly lock the private `m_mutex` prior to calling this method.
|
||||
*
|
||||
* @param mwmId The newly addded MWM.
|
||||
*/
|
||||
void Invalidate(MwmSet::MwmId const & mwmId);
|
||||
@@ -313,6 +316,19 @@ public:
|
||||
*/
|
||||
void SetTrafficUpdateCallbackFn(TrafficUpdateCallbackFn && fn);
|
||||
|
||||
/**
|
||||
* @brief Runs a function guarded by the traffic manager mutex.
|
||||
*
|
||||
* This locks `m_mutex`, then runs `f` and releases the mutex.
|
||||
*
|
||||
* @param f
|
||||
*/
|
||||
void RunSynchronized(std::function<void()> f)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
f();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user