[traffic] Defer TrafficManager startup until MWMs are first updated

Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
mvglasow
2025-05-16 02:01:06 +03:00
parent e94c23d538
commit c8d5a07262
2 changed files with 25 additions and 14 deletions

View File

@@ -73,6 +73,7 @@ TrafficManager::TrafficManager(DataSource & dataSource,
, m_maxCacheSizeBytes(maxCacheSizeBytes) , m_maxCacheSizeBytes(maxCacheSizeBytes)
#endif #endif
, m_isRunning(true) , m_isRunning(true)
, m_isStarted(false)
, m_isPaused(false) , m_isPaused(false)
, m_thread(&TrafficManager::ThreadRoutine, this) , m_thread(&TrafficManager::ThreadRoutine, this)
{ {
@@ -211,6 +212,7 @@ void TrafficManager::UpdateActiveMwms(m2::RectD const & rect,
{ {
std::lock_guard<std::mutex> lock(m_mutex); std::lock_guard<std::mutex> lock(m_mutex);
m_isStarted = true;
m_activeMwmsChanged = true; m_activeMwmsChanged = true;
activeMwms.clear(); activeMwms.clear();
for (auto const & mwm : mwms) for (auto const & mwm : mwms)
@@ -660,6 +662,8 @@ bool TrafficManager::WaitForRequest(std::vector<MwmSet::MwmId> & mwms)
if (!m_isRunning) if (!m_isRunning)
return false; return false;
if (m_isStarted)
{
// if we have feeds in the queue, return immediately // if we have feeds in the queue, return immediately
if (!m_feedQueue.empty()) if (!m_feedQueue.empty())
{ {
@@ -676,6 +680,7 @@ bool TrafficManager::WaitForRequest(std::vector<MwmSet::MwmId> & mwms)
m_isPollNeeded = true; m_isPollNeeded = true;
return true; return true;
} }
}
LOG(LINFO, ("nothing to do for now, waiting for timeout or notification")); LOG(LINFO, ("nothing to do for now, waiting for timeout or notification"));
bool const timeout = !m_condition.wait_for(lock, kUpdateInterval, [this] bool const timeout = !m_condition.wait_for(lock, kUpdateInterval, [this]
@@ -688,6 +693,7 @@ bool TrafficManager::WaitForRequest(std::vector<MwmSet::MwmId> & mwms)
return false; return false;
// this works as long as wait timeout is at least equal to the poll interval // this works as long as wait timeout is at least equal to the poll interval
if (m_isStarted)
m_isPollNeeded |= timeout; m_isPollNeeded |= timeout;
LOG(LINFO, ("timeout:", timeout, "active MWMs changed:", m_activeMwmsChanged)); LOG(LINFO, ("timeout:", timeout, "active MWMs changed:", m_activeMwmsChanged));

View File

@@ -465,6 +465,11 @@ private:
// which allows a client to make conditional requests. // which allows a client to make conditional requests.
std::map<MwmSet::MwmId, std::string> m_trafficETags; std::map<MwmSet::MwmId, std::string> m_trafficETags;
/**
* Whether the traffic manager should begin receiving information.
*/
std::atomic<bool> m_isStarted;
std::atomic<bool> m_isPaused; std::atomic<bool> m_isPaused;
/** /**