diff options
author | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-08-08 17:15:25 +0300 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2019-10-16 15:37:10 +0300 |
commit | a8558379dbbc92ca75c9c3057990ac6c78a06e1f (patch) | |
tree | 1d1844ec5855eb77121e772c4e3cc083e8fc217f /platform/android/src/timer.cpp | |
parent | 050b3360ecef908d02141ed445d93ba5b4c9c75f (diff) | |
download | qtlocation-mapboxgl-a8558379dbbc92ca75c9c3057990ac6c78a06e1f.tar.gz |
[android] Check flag before runnable task invocation
Diffstat (limited to 'platform/android/src/timer.cpp')
-rw-r--r-- | platform/android/src/timer.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/platform/android/src/timer.cpp b/platform/android/src/timer.cpp index a45c48702e..1d3d05c843 100644 --- a/platform/android/src/timer.cpp +++ b/platform/android/src/timer.cpp @@ -3,6 +3,7 @@ #include <mbgl/util/run_loop.hpp> #include <mbgl/util/timer.hpp> +#include <atomic> #include <functional> namespace mbgl { @@ -10,7 +11,7 @@ namespace util { class Timer::Impl : public RunLoop::Impl::Runnable { public: - Impl() = default; + Impl() : active(false) {} ~Impl() { stop(); @@ -25,9 +26,11 @@ public: due = (timeout == Duration::max()) ? std::chrono::time_point<Clock>::max() : Clock::now() + timeout; loop->addRunnable(this); + active = true; } void stop() { + active = false; loop->removeRunnable(this); } @@ -45,8 +48,10 @@ public: } void runTask() override { - reschedule(); - task(); + if (active) { + reschedule(); + task(); + } } private: @@ -56,6 +61,7 @@ private: RunLoop::Impl* loop = reinterpret_cast<RunLoop::Impl*>(RunLoop::getLoopHandle()); std::function<void()> task; + std::atomic<bool> active; }; Timer::Timer() : impl(std::make_unique<Impl>()) { |