From daaf52d27ddaac5c01addb487f717c5dd5054d90 Mon Sep 17 00:00:00 2001 From: mvglasow Date: Fri, 6 Jun 2025 20:37:28 +0300 Subject: [PATCH] [traffic] Fix Push() and make it public for testing Signed-off-by: mvglasow --- map/traffic_manager.cpp | 11 +++++++---- map/traffic_manager.hpp | 22 +++++++++++----------- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/map/traffic_manager.cpp b/map/traffic_manager.cpp index 82f9b983c..6d16e4bec 100644 --- a/map/traffic_manager.cpp +++ b/map/traffic_manager.cpp @@ -372,9 +372,12 @@ bool TrafficManager::Poll() void TrafficManager::Push(traffxml::TraffFeed feed) { - std::lock_guard lock(m_mutex); - m_feedQueue.push_back(feed); - // TODO should we update m_lastResponseTime? + { + std::lock_guard lock(m_mutex); + m_feedQueue.push_back(feed); + // TODO should we update m_lastResponseTime? + } + m_condition.notify_one(); } void TrafficManager::ConsolidateFeedQueue() @@ -591,7 +594,7 @@ bool TrafficManager::WaitForRequest() LOG(LINFO, ("nothing to do for now, waiting for timeout or notification")); bool const timeout = !m_condition.wait_for(lock, kUpdateInterval, [this] { - return !m_isRunning || (m_activeMwmsChanged && !IsTestMode()); + return !m_isRunning || (m_activeMwmsChanged && !IsTestMode()) || !m_feedQueue.empty(); }); // check again if we got terminated while waiting (or woken up because we got terminated) diff --git a/map/traffic_manager.hpp b/map/traffic_manager.hpp index 43b8cc1f9..97c7f0196 100644 --- a/map/traffic_manager.hpp +++ b/map/traffic_manager.hpp @@ -204,6 +204,17 @@ public: */ void SetTestMode(); + /** + * @brief Processes a traffic feed received through a push operation. + * + * Push is safe to call from any thread. + * + * Push operations are not supported on all platforms. + * + * @param feed The traffic feed. + */ + void Push(traffxml::TraffFeed feed); + private: /** * @brief Holds information about pending or previous traffic requests pertaining to an MWM. @@ -313,17 +324,6 @@ private: */ bool Poll(); - /** - * @brief Processes a traffic feed received through a push operation. - * - * Push is safe to call from any thread. - * - * Push operations are not supported on all platforms. - * - * @param feed The traffic feed. - */ - void Push(traffxml::TraffFeed feed); - /** * @brief Consolidates the feed queue. *