diff --git a/base/deferred_task.cpp b/base/deferred_task.cpp index c769dab253..a3755dbab4 100644 --- a/base/deferred_task.cpp +++ b/base/deferred_task.cpp @@ -1,8 +1,11 @@ #include "deferred_task.hpp" -DeferredTask::DeferredTask(TDuration duration) : m_duration(duration) +namespace my { - m_thread = thread([this] { +DeferredTask::DeferredTask(TDuration const & duration) : m_duration(duration) +{ + m_thread = thread([this] + { unique_lock l(m_mutex); while (!m_terminate) { @@ -15,11 +18,15 @@ DeferredTask::DeferredTask(TDuration duration) : m_duration(duration) if (m_cv.wait_for(l, m_duration) != cv_status::timeout) continue; - auto local_fn = move(m_fn); + auto fn = move(m_fn); m_fn = nullptr; - l.unlock(); - local_fn(); - l.lock(); + + if (fn) + { + l.unlock(); + fn(); + l.lock(); + } } }); } @@ -42,3 +49,4 @@ void DeferredTask::Drop() } m_cv.notify_one(); } +} // namespace my diff --git a/base/deferred_task.hpp b/base/deferred_task.hpp index 517953150d..6ef785ef02 100644 --- a/base/deferred_task.hpp +++ b/base/deferred_task.hpp @@ -1,12 +1,13 @@ #pragma once -#include "std/thread.hpp" #include "std/chrono.hpp" -#include "std/mutex.hpp" #include "std/condition_variable.hpp" #include "std/function.hpp" +#include "std/mutex.hpp" +#include "std/thread.hpp" - +namespace my +{ class DeferredTask { using TDuration = duration; @@ -18,12 +19,12 @@ class DeferredTask bool m_terminate = false; public: - DeferredTask(TDuration duration); + DeferredTask(TDuration const & duration); ~DeferredTask(); void Drop(); - template + template void RestartWith(TFn const && fn) { { @@ -33,3 +34,4 @@ public: m_cv.notify_one(); } }; +} // namespace my diff --git a/map/framework.cpp b/map/framework.cpp index f1ebea941f..627f59bb6e 100644 --- a/map/framework.cpp +++ b/map/framework.cpp @@ -288,7 +288,7 @@ Framework::Framework() , m_bmManager(*this) , m_fixedSearchResults(0) , m_lastReportedCountry(kInvalidCountryId) - , m_watchdogCountryUpdate(seconds(2)) + , m_deferredCountryUpdate(seconds(1)) { // Restore map style before classificator loading int mapStyle = MapStyleLight; @@ -946,15 +946,19 @@ void Framework::ClearAllCaches() void Framework::OnCheckUpdateCurrentCountry(m2::PointF const & pt, int zoomLevel) { if (zoomLevel <= scales::GetUpperWorldScale()) - m_watchdogCountryUpdate.Drop(); + m_deferredCountryUpdate.Drop(); else - m_watchdogCountryUpdate.RestartWith([this, pt, zoomLevel]{ + m_deferredCountryUpdate.RestartWith([this, pt, zoomLevel] + { OnUpdateCurrentCountry(pt, zoomLevel); }); } void Framework::OnUpdateCurrentCountry(m2::PointF const & pt, int zoomLevel) { + if (zoomLevel <= scales::GetUpperWorldScale()) + return; + storage::TCountryId newCountryId = m_infoGetter->GetRegionCountryId(m2::PointD(pt)); if (newCountryId == m_lastReportedCountry) diff --git a/map/framework.hpp b/map/framework.hpp index 44ea8e6cc8..1aee5ce77d 100644 --- a/map/framework.hpp +++ b/map/framework.hpp @@ -42,7 +42,6 @@ #include "std/list.hpp" #include "std/shared_ptr.hpp" #include "std/target_os.hpp" -#include "std/thread.hpp" #include "std/unique_ptr.hpp" #include "std/vector.hpp" #include "std/weak_ptr.hpp" @@ -128,7 +127,7 @@ protected: double m_startForegroundTime; storage::Storage m_storage; - DeferredTask m_watchdogCountryUpdate; + my::DeferredTask m_deferredCountryUpdate; location::TMyPositionModeChanged m_myPositionListener;