From c8d5a07262755d6b79c8b96e46889ef1e40880f0 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Fri, 16 May 2025 02:01:06 +0300 Subject: [PATCH] [traffic] Defer TrafficManager startup until MWMs are first updated Signed-off-by: mvglasow --- map/traffic_manager.cpp | 34 ++++++++++++++++++++-------------- map/traffic_manager.hpp | 5 +++++ 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/map/traffic_manager.cpp b/map/traffic_manager.cpp index 62a7148ed..b890cc269 100644 --- a/map/traffic_manager.cpp +++ b/map/traffic_manager.cpp @@ -73,6 +73,7 @@ TrafficManager::TrafficManager(DataSource & dataSource, , m_maxCacheSizeBytes(maxCacheSizeBytes) #endif , m_isRunning(true) + , m_isStarted(false) , m_isPaused(false) , m_thread(&TrafficManager::ThreadRoutine, this) { @@ -211,6 +212,7 @@ void TrafficManager::UpdateActiveMwms(m2::RectD const & rect, { std::lock_guard lock(m_mutex); + m_isStarted = true; m_activeMwmsChanged = true; activeMwms.clear(); for (auto const & mwm : mwms) @@ -660,21 +662,24 @@ bool TrafficManager::WaitForRequest(std::vector & mwms) if (!m_isRunning) return false; - // if we have feeds in the queue, return immediately - if (!m_feedQueue.empty()) + if (m_isStarted) { - LOG(LINFO, ("feed queue not empty, returning immediately")); - return true; - } + // if we have feeds in the queue, return immediately + if (!m_feedQueue.empty()) + { + LOG(LINFO, ("feed queue not empty, returning immediately")); + return true; + } - // if update interval has elapsed, return immediately - auto const currentTime = steady_clock::now(); - auto const passedSeconds = currentTime - m_lastResponseTime; - if (passedSeconds >= kUpdateInterval) - { - LOG(LINFO, ("last response was", passedSeconds, "ago, returning immediately")); - m_isPollNeeded = true; - return true; + // if update interval has elapsed, return immediately + auto const currentTime = steady_clock::now(); + auto const passedSeconds = currentTime - m_lastResponseTime; + if (passedSeconds >= kUpdateInterval) + { + LOG(LINFO, ("last response was", passedSeconds, "ago, returning immediately")); + m_isPollNeeded = true; + return true; + } } LOG(LINFO, ("nothing to do for now, waiting for timeout or notification")); @@ -688,7 +693,8 @@ bool TrafficManager::WaitForRequest(std::vector & mwms) return false; // this works as long as wait timeout is at least equal to the poll interval - m_isPollNeeded |= timeout; + if (m_isStarted) + m_isPollNeeded |= timeout; LOG(LINFO, ("timeout:", timeout, "active MWMs changed:", m_activeMwmsChanged)); return true; diff --git a/map/traffic_manager.hpp b/map/traffic_manager.hpp index e384dbea4..64ab8be26 100644 --- a/map/traffic_manager.hpp +++ b/map/traffic_manager.hpp @@ -465,6 +465,11 @@ private: // which allows a client to make conditional requests. std::map m_trafficETags; + /** + * Whether the traffic manager should begin receiving information. + */ + std::atomic m_isStarted; + std::atomic m_isPaused; /**