[traffic] Fix Push() and make it public for testing

Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
mvglasow
2025-06-06 20:37:28 +03:00
parent ba9980ba36
commit daaf52d27d
2 changed files with 18 additions and 15 deletions

View File

@@ -372,9 +372,12 @@ bool TrafficManager::Poll()
void TrafficManager::Push(traffxml::TraffFeed feed)
{
std::lock_guard<std::mutex> lock(m_mutex);
m_feedQueue.push_back(feed);
// TODO should we update m_lastResponseTime?
{
std::lock_guard<std::mutex> 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)

View File

@@ -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.
*