diff --git a/libs/map/traffic_manager.cpp b/libs/map/traffic_manager.cpp index 523f8adaa..3b757f55f 100644 --- a/libs/map/traffic_manager.cpp +++ b/libs/map/traffic_manager.cpp @@ -206,8 +206,7 @@ void TrafficManager::OnChangeRoutingSessionState(routing::SessionState previous, LOG(LINFO, ("Routing session state changed from", previous, "to", current)); LOG(LINFO, ("Running on thread", std::this_thread::get_id())); - m_observerInhibited = ((current == routing::SessionState::RouteBuilding) - || (current == routing::SessionState::RouteRebuilding)); + m_routingSessionState = current; /* * Filter based on session state (see routing_callbacks.hpp for states and transitions). @@ -806,7 +805,7 @@ void TrafficManager::OnTrafficDataUpdate() auto const storageAge = currentTime - m_lastStorageUpdate; notifyDrape = (drapeAge >= kDrapeUpdateInterval); updateStorage = (storageAge >= kStorageUpdateInterval); - if (!m_observerInhibited) + if (!IsObserverInhibited()) { /* * To avoid resetting the route over and over again while building, inhibit periodic updates diff --git a/libs/map/traffic_manager.hpp b/libs/map/traffic_manager.hpp index ad1443653..c99ae5bd4 100644 --- a/libs/map/traffic_manager.hpp +++ b/libs/map/traffic_manager.hpp @@ -533,6 +533,20 @@ private: std::for_each(activeMwms.begin(), activeMwms.end(), std::forward(f)); } + /** + * @brief Whether updates to the observer are currently inhibited. + * + * Updates are inhibited while a route calculation is in progress. In this state, the observer + * receives traffic updates only if the queue has run empty, not if nore locations are waiting + * to be decoded. + * + * Inhibtiting the observer is necessary as traffic updates during route calculation will cause + * it to restart from scratch. Once the route has been calculated, updates will trigger a + * recalculation, which is much faster (seconds or less). + */ + bool IsObserverInhibited() const { return (m_routingSessionState == routing::SessionState::RouteBuilding) + || (m_routingSessionState == routing::SessionState::RouteRebuilding); } + DataSource & m_dataSource; CountryInfoGetterFn m_countryInfoGetterFn; CountryParentNameGetterFn m_countryParentNameGetterFn; @@ -546,6 +560,14 @@ private: */ routing::RoutingSession & m_routingSession; + /** + * @brief Cached state of the routing session. + * + * `m_routingSession` methods which query the state may only be called from the GUI thread, + * therefore we are caching this value when we get notified of a change. + */ + routing::SessionState m_routingSessionState = routing::SessionState::NoValidRoute; + df::DrapeEngineSafePtr m_drapeEngine; std::atomic m_currentDataVersion; @@ -651,19 +673,6 @@ private: */ std::chrono::time_point m_lastObserverUpdate; - /** - * @brief Whether updates to the observer are currently inhibited. - * - * Updates are inhibited while a route calculation is in progress. In this state, the observer - * receives traffic updates only if the queue has run empty, not if nore locations are waiting - * to be decoded. - * - * Inhibtiting the observer is necessary as traffic updates during route calculation will cause - * it to restart from scratch. Once the route has been calculated, updates will trigger a - * recalculation, which is much faster (seconds or less). - */ - bool m_observerInhibited = false; - /** * @brief When the cache file was last updated. */