diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-07-01 12:21:22 +0300 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-07-05 21:04:27 +0300 |
commit | 70d4ebb347b4ee0675c8e0078a8f69eb567bd252 (patch) | |
tree | 031220f57126806217a37152c8332a1a7b59a649 | |
parent | 2bf4e20052e827a4f69dd718ba659f66edccc6df (diff) | |
download | qtlocation-mapboxgl-70d4ebb347b4ee0675c8e0078a8f69eb567bd252.tar.gz |
[android] Fix default RunLoop not stopping
stop() for default RunLoop is only used by unit tests and we need
to wake the ALooper to get past run().
-rw-r--r-- | platform/android/src/run_loop.cpp | 12 | ||||
-rw-r--r-- | platform/android/src/run_loop_impl.hpp | 7 |
2 files changed, 13 insertions, 6 deletions
diff --git a/platform/android/src/run_loop.cpp b/platform/android/src/run_loop.cpp index 7a28a6139c..591cb31fd3 100644 --- a/platform/android/src/run_loop.cpp +++ b/platform/android/src/run_loop.cpp @@ -36,9 +36,15 @@ int looperCallbackDefault(int fd, int, void* data) { int buffer[1]; while (read(fd, buffer, sizeof(buffer)) > 0) {} - auto runLoop = reinterpret_cast<RunLoop*>(data); + auto runLoopImpl = reinterpret_cast<RunLoop::Impl*>(data); + auto runLoop = runLoopImpl->runLoop; + runLoop->runOnce(); + if (!runLoopImpl->running) { + ALooper_wake(runLoopImpl->loop); + } + return 1; } @@ -47,7 +53,7 @@ int looperCallbackDefault(int fd, int, void* data) { namespace mbgl { namespace util { -RunLoop::Impl::Impl(RunLoop* runLoop, RunLoop::Type type) { +RunLoop::Impl::Impl(RunLoop* runLoop_, RunLoop::Type type) : runLoop(runLoop_) { using namespace mbgl::android; detach = attach_jni_thread(theJVM, &env, ""); @@ -73,7 +79,7 @@ RunLoop::Impl::Impl(RunLoop* runLoop, RunLoop::Type type) { break; case Type::Default: ret = ALooper_addFd(loop, fds[PIPE_OUT], ALOOPER_POLL_CALLBACK, - ALOOPER_EVENT_INPUT, looperCallbackDefault, runLoop); + ALOOPER_EVENT_INPUT, looperCallbackDefault, this); break; } diff --git a/platform/android/src/run_loop_impl.hpp b/platform/android/src/run_loop_impl.hpp index d855728b60..1ca3dbc61a 100644 --- a/platform/android/src/run_loop_impl.hpp +++ b/platform/android/src/run_loop_impl.hpp @@ -38,6 +38,10 @@ public: Milliseconds processRunnables(); + ALooper* loop = nullptr; + RunLoop* runLoop = nullptr; + util::Atomic<bool> running; + private: friend RunLoop; @@ -46,9 +50,6 @@ private: JNIEnv *env = nullptr; bool detach = false; - ALooper* loop = nullptr; - util::Atomic<bool> running; - std::recursive_mutex mtx; std::list<Runnable*> runnables; }; |