summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-08-08 17:15:25 +0300
committerzmiao <miao.zhao@mapbox.com>2019-10-17 16:17:28 +0300
commit1e9f490df1d02fa4b87e4f1f8a0d4d32d9df1e82 (patch)
treee81c2d1e22eea1e19490328e0de97dfc1eafba6d
parent050b3360ecef908d02141ed445d93ba5b4c9c75f (diff)
downloadqtlocation-mapboxgl-1e9f490df1d02fa4b87e4f1f8a0d4d32d9df1e82.tar.gz
[android] Check flag before runnable task invocation
-rw-r--r--next/render-test/CMakeLists.txt5
-rw-r--r--platform/android/src/async_task.cpp9
-rw-r--r--platform/android/src/timer.cpp12
3 files changed, 20 insertions, 6 deletions
diff --git a/next/render-test/CMakeLists.txt b/next/render-test/CMakeLists.txt
index b3aa20ba62..09767494c7 100644
--- a/next/render-test/CMakeLists.txt
+++ b/next/render-test/CMakeLists.txt
@@ -32,6 +32,11 @@ target_include_directories(
PUBLIC ${MBGL_ROOT}/render-test/include ${MBGL_ROOT}/include
)
+target_include_directories(
+ mbgl-render-test
+ PUBLIC ${MBGL_ROOT}/render-test/include ${MBGL_ROOT}/include
+)
+
include(${PROJECT_SOURCE_DIR}/vendor/boost.cmake)
target_link_libraries(
diff --git a/platform/android/src/async_task.cpp b/platform/android/src/async_task.cpp
index 6c14e96fa6..0a4d90a275 100644
--- a/platform/android/src/async_task.cpp
+++ b/platform/android/src/async_task.cpp
@@ -16,6 +16,7 @@ public:
}
~Impl() {
+ queued = true;
loop->removeRunnable(this);
}
@@ -31,9 +32,11 @@ public:
}
void runTask() override {
- loop->removeRunnable(this);
- queued = true;
- task();
+ if (!queued) {
+ queued = true;
+ loop->removeRunnable(this);
+ task();
+ }
}
private:
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>()) {