summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2016-07-04 19:22:21 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2016-07-05 21:04:27 +0300
commite579199ac12b58e1099bba5f880a19588c867429 (patch)
tree78bd82a7aded3d5791a9c30bedc9fd1087483913
parent70d4ebb347b4ee0675c8e0078a8f69eb567bd252 (diff)
downloadqtlocation-mapboxgl-e579199ac12b58e1099bba5f880a19588c867429.tar.gz
[android] Fix a bug when canceling tasks
If the next task in the queue gets canceled, we need to adjust the iterator to the next task, otherwise a canceled task gets executed.
-rw-r--r--platform/android/src/run_loop.cpp16
-rw-r--r--platform/android/src/run_loop_impl.hpp1
2 files changed, 12 insertions, 5 deletions
diff --git a/platform/android/src/run_loop.cpp b/platform/android/src/run_loop.cpp
index 591cb31fd3..6c6d3555e9 100644
--- a/platform/android/src/run_loop.cpp
+++ b/platform/android/src/run_loop.cpp
@@ -123,10 +123,16 @@ void RunLoop::Impl::addRunnable(Runnable* runnable) {
void RunLoop::Impl::removeRunnable(Runnable* runnable) {
std::lock_guard<std::recursive_mutex> lock(mtx);
- if (runnable->iter != runnables.end()) {
- runnables.erase(runnable->iter);
- runnable->iter = runnables.end();
+ if (runnable->iter == runnables.end()) {
+ return;
+ }
+
+ if (nextRunnable == runnable->iter) {
+ ++nextRunnable;
}
+
+ runnables.erase(runnable->iter);
+ runnable->iter = runnables.end();
}
void RunLoop::Impl::initRunnable(Runnable* runnable) {
@@ -141,8 +147,8 @@ Milliseconds RunLoop::Impl::processRunnables() {
// O(N) but in the render thread where we get tons
// of messages, the size of the list is usually 1~2.
- for (auto iter = runnables.begin(); iter != runnables.end();) {
- Runnable* runnable = *(iter++);
+ for (nextRunnable = runnables.begin(); nextRunnable != runnables.end();) {
+ Runnable* runnable = *(nextRunnable++);
auto const dueTime = runnable->dueTime();
if (dueTime <= now) {
diff --git a/platform/android/src/run_loop_impl.hpp b/platform/android/src/run_loop_impl.hpp
index 1ca3dbc61a..cb553d1f8a 100644
--- a/platform/android/src/run_loop_impl.hpp
+++ b/platform/android/src/run_loop_impl.hpp
@@ -52,6 +52,7 @@ private:
std::recursive_mutex mtx;
std::list<Runnable*> runnables;
+ std::list<Runnable*>::iterator nextRunnable;
};
} // namespace util