[traffic] Update clear/purge logic to use update mechanism

Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
mvglasow
2025-06-15 20:46:25 +03:00
parent 26aa5e5f54
commit 173b5e1718
2 changed files with 17 additions and 3 deletions

View File

@@ -157,7 +157,6 @@ void TrafficManager::Clear()
#endif
m_messageCache.clear();
m_feedQueue.clear();
m_allMwmColoring.clear();
m_mwmCache.clear();
// TODO figure out which of the ones below we still need
@@ -411,6 +410,12 @@ void TrafficManager::Push(traffxml::TraffFeed feed)
}
void TrafficManager::PurgeExpiredMessages()
{
PurgeExpiredMessagesImpl();
OnTrafficDataUpdate();
}
void TrafficManager::PurgeExpiredMessagesImpl()
{
std::lock_guard<std::mutex> lock(m_mutex);
LOG(LINFO, ("before:", m_messageCache.size(), "message(s)"));
@@ -549,7 +554,7 @@ void TrafficManager::ThreadRoutine()
if (steady_clock::now() - lastPurged >= kPurgeInterval)
{
lastPurged == steady_clock::now();
PurgeExpiredMessages();
PurgeExpiredMessagesImpl();
}
LOG(LINFO, ("active MWMs changed:", m_activeMwmsChanged, ", poll needed:", m_isPollNeeded));

View File

@@ -219,7 +219,7 @@ public:
/**
* @brief Purges expired messages from the cache.
*
* This method is safe to call from any thread.
* This method is safe to call from any thread, except for the traffic worker thread.
*/
void PurgeExpiredMessages();
@@ -352,6 +352,15 @@ private:
*/
bool Poll();
/**
* @brief Purges expired messages from the cache.
*
* This is the internal conterpart of `PurgeExpiredMessages()`. It is safe to call from any
* thread. Unlike `PurgeExpiredMessages()`, it does not wake the worker thread, making it suitable
* for use on the worker thread.
*/
void PurgeExpiredMessagesImpl();
/**
* @brief Consolidates the feed queue.
*