diff options
Diffstat (limited to 'platform')
-rw-r--r-- | platform/android/src/run_loop.cpp | 16 | ||||
-rw-r--r-- | platform/android/src/run_loop_impl.hpp | 1 |
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 |