mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-22 22:23:44 +00:00
[traffic] Defer TrafficManager startup until MWMs are first updated
Signed-off-by: mvglasow <michael -at- vonglasow.com>
This commit is contained in:
@@ -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,21 +662,24 @@ bool TrafficManager::WaitForRequest(std::vector<MwmSet::MwmId> & mwms)
|
|||||||
if (!m_isRunning)
|
if (!m_isRunning)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// if we have feeds in the queue, return immediately
|
if (m_isStarted)
|
||||||
if (!m_feedQueue.empty())
|
|
||||||
{
|
{
|
||||||
LOG(LINFO, ("feed queue not empty, returning immediately"));
|
// if we have feeds in the queue, return immediately
|
||||||
return true;
|
if (!m_feedQueue.empty())
|
||||||
}
|
{
|
||||||
|
LOG(LINFO, ("feed queue not empty, returning immediately"));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// if update interval has elapsed, return immediately
|
// if update interval has elapsed, return immediately
|
||||||
auto const currentTime = steady_clock::now();
|
auto const currentTime = steady_clock::now();
|
||||||
auto const passedSeconds = currentTime - m_lastResponseTime;
|
auto const passedSeconds = currentTime - m_lastResponseTime;
|
||||||
if (passedSeconds >= kUpdateInterval)
|
if (passedSeconds >= kUpdateInterval)
|
||||||
{
|
{
|
||||||
LOG(LINFO, ("last response was", passedSeconds, "ago, returning immediately"));
|
LOG(LINFO, ("last response was", passedSeconds, "ago, returning immediately"));
|
||||||
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"));
|
||||||
@@ -688,7 +693,8 @@ 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
|
||||||
m_isPollNeeded |= timeout;
|
if (m_isStarted)
|
||||||
|
m_isPollNeeded |= timeout;
|
||||||
|
|
||||||
LOG(LINFO, ("timeout:", timeout, "active MWMs changed:", m_activeMwmsChanged));
|
LOG(LINFO, ("timeout:", timeout, "active MWMs changed:", m_activeMwmsChanged));
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user