summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2016-07-04 20:23:49 +0300
committerThiago Marcos P. Santos <thiago@mapbox.com>2016-07-05 21:04:27 +0300
commit13cd75f099c92b6f0862db00eee8ff4a78a73316 (patch)
treeaa506edf786cfbca677c4760fa2da2a5698bc831
parentb3b86f9be4187fc82f34188c627c1466c79ad041 (diff)
downloadqtlocation-mapboxgl-13cd75f099c92b6f0862db00eee8ff4a78a73316.tar.gz
[android] Do not create Timers on Default main loops
Not supported, because we don't have control over the Looper timeout like we do for Loopers we create. On the main thread, Android takes care of making the application sleep and sets an arbitrary timeout. This could be properly fixed by implementing timers in Java, but we don't really have the use case of timers in the main thread.
-rw-r--r--platform/android/src/run_loop.cpp2
-rw-r--r--platform/android/src/run_loop_impl.hpp1
-rw-r--r--platform/android/src/timer.cpp4
-rw-r--r--test/util/timer.cpp12
4 files changed, 12 insertions, 7 deletions
diff --git a/platform/android/src/run_loop.cpp b/platform/android/src/run_loop.cpp
index 6c6d3555e9..1656565e8e 100644
--- a/platform/android/src/run_loop.cpp
+++ b/platform/android/src/run_loop.cpp
@@ -80,6 +80,8 @@ RunLoop::Impl::Impl(RunLoop* runLoop_, RunLoop::Type type) : runLoop(runLoop_) {
case Type::Default:
ret = ALooper_addFd(loop, fds[PIPE_OUT], ALOOPER_POLL_CALLBACK,
ALOOPER_EVENT_INPUT, looperCallbackDefault, this);
+ running = true;
+ isDefaultLoop = true;
break;
}
diff --git a/platform/android/src/run_loop_impl.hpp b/platform/android/src/run_loop_impl.hpp
index cb553d1f8a..9622efb368 100644
--- a/platform/android/src/run_loop_impl.hpp
+++ b/platform/android/src/run_loop_impl.hpp
@@ -41,6 +41,7 @@ public:
ALooper* loop = nullptr;
RunLoop* runLoop = nullptr;
util::Atomic<bool> running;
+ bool isDefaultLoop = false;
private:
friend RunLoop;
diff --git a/platform/android/src/timer.cpp b/platform/android/src/timer.cpp
index 81cf0a68b0..6c0dc81eca 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 <cassert>
#include <functional>
namespace mbgl {
@@ -11,6 +12,7 @@ namespace util {
class Timer::Impl : public RunLoop::Impl::Runnable {
public:
Impl() {
+ assert(!loop->isDefaultLoop);
loop->initRunnable(this);
}
@@ -35,7 +37,7 @@ public:
void reschedule() {
if (repeat != Duration::zero()) {
due = Clock::now() + repeat;
- loop->addRunnable(this);
+ loop->wake();
} else {
stop();
}
diff --git a/test/util/timer.cpp b/test/util/timer.cpp
index f6253ab6d3..c37440ed40 100644
--- a/test/util/timer.cpp
+++ b/test/util/timer.cpp
@@ -10,7 +10,7 @@
using namespace mbgl::util;
TEST(Timer, TEST_REQUIRES_ACCURATE_TIMING(Basic)) {
- RunLoop loop;
+ RunLoop loop(RunLoop::Type::New);
Timer timer;
@@ -34,7 +34,7 @@ TEST(Timer, TEST_REQUIRES_ACCURATE_TIMING(Basic)) {
}
TEST(Timer, TEST_REQUIRES_ACCURATE_TIMING(Repeat)) {
- RunLoop loop;
+ RunLoop loop(RunLoop::Type::New);
Timer timer;
@@ -60,7 +60,7 @@ TEST(Timer, TEST_REQUIRES_ACCURATE_TIMING(Repeat)) {
}
TEST(Timer, TEST_REQUIRES_ACCURATE_TIMING(Stop)) {
- RunLoop loop;
+ RunLoop loop(RunLoop::Type::New);
Timer timer1;
Timer timer2;
@@ -96,7 +96,7 @@ TEST(Timer, TEST_REQUIRES_ACCURATE_TIMING(Stop)) {
}
TEST(Timer, TEST_REQUIRES_ACCURATE_TIMING(DestroyShouldStop)) {
- RunLoop loop;
+ RunLoop loop(RunLoop::Type::New);
auto timer1 = std::make_unique<Timer>();
Timer timer2;
@@ -132,7 +132,7 @@ TEST(Timer, TEST_REQUIRES_ACCURATE_TIMING(DestroyShouldStop)) {
}
TEST(Timer, TEST_REQUIRES_ACCURATE_TIMING(StartOverrides)) {
- RunLoop loop;
+ RunLoop loop(RunLoop::Type::New);
Timer timer;
@@ -166,7 +166,7 @@ TEST(Timer, TEST_REQUIRES_ACCURATE_TIMING(StartOverrides)) {
}
TEST(Timer, TEST_REQUIRES_ACCURATE_TIMING(CanStopNonStartedTimer)) {
- RunLoop loop;
+ RunLoop loop(RunLoop::Type::New);
Timer timer;
timer.stop();