mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-21 05:43:37 +00:00
[traffic] Refactor m_feeds to m_feedQueue
Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
@@ -335,7 +335,7 @@ bool TrafficManager::Poll()
|
|||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
m_feeds.push_back(feed);
|
m_feedQueue.push_back(feed);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -349,21 +349,21 @@ bool TrafficManager::Poll()
|
|||||||
void TrafficManager::Push(traffxml::TraffFeed feed)
|
void TrafficManager::Push(traffxml::TraffFeed feed)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
m_feeds.push_back(feed);
|
m_feedQueue.push_back(feed);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrafficManager::UpdateMessageCache(std::map<std::string, traffxml::TraffMessage> & cache)
|
void TrafficManager::UpdateMessageCache(std::map<std::string, traffxml::TraffMessage> & cache)
|
||||||
{
|
{
|
||||||
traffxml::TraffFeed feed;
|
traffxml::TraffFeed feed;
|
||||||
// Thread-safe iteration over m_feeds, releasing the mutex during the loop
|
// Thread-safe iteration over m_feedQueue, releasing the mutex during the loop
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::lock_guard<std::mutex> lock(m_mutex);
|
std::lock_guard<std::mutex> lock(m_mutex);
|
||||||
if (!m_feeds.empty())
|
if (!m_feedQueue.empty())
|
||||||
{
|
{
|
||||||
feed = m_feeds.front();
|
feed = m_feedQueue.front();
|
||||||
m_feeds.erase(m_feeds.begin());
|
m_feedQueue.erase(m_feedQueue.begin());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
@@ -535,7 +535,7 @@ void TrafficManager::ThreadRoutine()
|
|||||||
// TODO set failed status somewhere and retry
|
// TODO set failed status somewhere and retry
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
LOG(LINFO, (m_feeds.size(), "feed(s) in queue"));
|
LOG(LINFO, (m_feedQueue.size(), "feed(s) in queue"));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO call on a temp struct, then unite with m_messageCache, processing only messages with changes
|
* TODO call on a temp struct, then unite with m_messageCache, processing only messages with changes
|
||||||
|
|||||||
@@ -237,10 +237,10 @@ private:
|
|||||||
void Push(traffxml::TraffFeed feed);
|
void Push(traffxml::TraffFeed feed);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Merges new messages from `m_feeds` into a message cache.
|
|
||||||
*
|
*
|
||||||
* Existing messages in `cache` will be overwritten by newer messages with the same ID in `m_feeds`.
|
* @brief Merges new messages from `m_feedQueue` into a message cache.
|
||||||
*
|
*
|
||||||
|
* Existing messages in `cache` will be overwritten by newer messages with the same ID in `m_feedQueue`.
|
||||||
* @param cache The message cache.
|
* @param cache The message cache.
|
||||||
*/
|
*/
|
||||||
void UpdateMessageCache(std::map<std::string, traffxml::TraffMessage> & cache);
|
void UpdateMessageCache(std::map<std::string, traffxml::TraffMessage> & cache);
|
||||||
@@ -503,10 +503,10 @@ private:
|
|||||||
/**
|
/**
|
||||||
* @brief Queue of feeds waiting to be processed.
|
* @brief Queue of feeds waiting to be processed.
|
||||||
*
|
*
|
||||||
* Threads must lock `m_mutex` before accessing `m_feeds`, as some platforms may receive feeds
|
* Threads must lock `m_mutex` before accessing `m_feedQueue`, as some platforms may receive feeds
|
||||||
* on multiple threads.
|
* on multiple threads.
|
||||||
*/
|
*/
|
||||||
std::vector<traffxml::TraffFeed> m_feeds;
|
std::vector<traffxml::TraffFeed> m_feedQueue;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Cache of all currently active TraFF messages.
|
* @brief Cache of all currently active TraFF messages.
|
||||||
|
|||||||
Reference in New Issue
Block a user