diff options
Diffstat (limited to 'include/mbgl')
-rw-r--r-- | include/mbgl/map/map.hpp | 15 | ||||
-rw-r--r-- | include/mbgl/util/uv.hpp | 2 | ||||
-rw-r--r-- | include/mbgl/util/uv_detail.hpp | 18 |
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(); } |