summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorLeith Bade <leith@leithalweapon.geek.nz>2014-11-09 22:36:37 +1100
committerLeith Bade <leith@leithalweapon.geek.nz>2014-11-09 22:36:37 +1100
commit28d66bb6f856b3836616f9574c38dbb9fe749d92 (patch)
treee668fa8f0a75c83ad47e659ec8bc731e965c2169 /include
parentb3e3c21129671884e130d34507057676484656b4 (diff)
downloadqtlocation-mapboxgl-28d66bb6f856b3836616f9574c38dbb9fe749d92.tar.gz
Add Map::pause/resume
Fixed bug after switching apps
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/map/map.hpp15
-rw-r--r--include/mbgl/util/uv.hpp2
-rw-r--r--include/mbgl/util/uv_detail.hpp18
3 files changed, 35 insertions, 0 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 43402fe2e5..f2f10665e0 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -45,6 +45,12 @@ public:
// function.
void stop(stop_callback cb = nullptr, void *data = nullptr);
+ // Pauses the render thread. The render thread will stop running but will not be terminated and will not lose state until resumed.
+ void pause();
+
+ // Resumes a paused render thread
+ void resume();
+
// Runs the map event loop. ONLY run this function when you want to get render a single frame
// with this map object. It will *not* spawn a separate thread and instead block until the
// frame is completely rendered.
@@ -145,6 +151,9 @@ private:
static void terminate(uv_async_t *async);
static void cleanup(uv_async_t *async);
+ // Checks if render thread needs to pause
+ void check_for_pause();
+
// Setup
void setup();
@@ -168,6 +177,12 @@ private:
std::unique_ptr<uv_async_t> async_cleanup;
private:
+ bool terminating = false;
+ bool is_paused = false;
+ std::unique_ptr<uv::mutex> mutex_pause;
+ std::unique_ptr<uv::cond> cond_resume;
+
+private:
// If cleared, the next time the render thread attempts to render the map, it will *actually*
// render the map.
std::atomic_flag is_clean = ATOMIC_FLAG_INIT;
diff --git a/include/mbgl/util/uv.hpp b/include/mbgl/util/uv.hpp
index 3c533cfbf8..0e828bb4f3 100644
--- a/include/mbgl/util/uv.hpp
+++ b/include/mbgl/util/uv.hpp
@@ -21,6 +21,8 @@ class thread;
class rwlock;
class loop;
class worker;
+class mutex;
+class cond;
}
diff --git a/include/mbgl/util/uv_detail.hpp b/include/mbgl/util/uv_detail.hpp
index 3bbfa4ac5a..112339c1b5 100644
--- a/include/mbgl/util/uv_detail.hpp
+++ b/include/mbgl/util/uv_detail.hpp
@@ -52,6 +52,7 @@ private:
};
class mutex {
+ friend class cond;
public:
inline mutex() {
if (uv_mutex_init(&mtx) != 0) {
@@ -66,6 +67,23 @@ private:
uv_mutex_t mtx;
};
+class cond {
+public:
+ inline cond() {
+ if (uv_cond_init(&cnd) != 0) {
+ throw std::runtime_error("failed to initialize condition variable");
+ }
+ }
+ inline ~cond() { uv_cond_destroy(&cnd); }
+ inline void signal() { uv_cond_signal(&cnd); }
+ inline void broadcast() { uv_cond_broadcast(&cnd); }
+ inline void wait(mutex &mtx) { uv_cond_wait(&cnd, &mtx.mtx); }
+ inline void timedwait(mutex &mtx, uint64_t timeout) { uv_cond_timedwait(&cnd, &mtx.mtx, timeout); }
+
+private:
+ uv_cond_t cnd;
+};
+
class lock {
public:
lock(mutex &mtx_) : mtx(mtx_) { mtx.lock(); }