diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 0cb055b59..f15fcd6df 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -14,6 +14,8 @@ #include #include #include +#include +#include namespace mbgl { @@ -180,10 +182,10 @@ private: bool terminating = false; bool pausing = false; bool is_paused = false; - std::unique_ptr mutex_run; - std::unique_ptr cond_run; - std::unique_ptr mutex_pause; - std::unique_ptr cond_pause; + std::mutex mutex_run; + std::condition_variable cond_run; + std::mutex mutex_pause; + std::condition_variable cond_pause; private: // If cleared, the next time the render thread attempts to render the map, it will *actually* diff --git a/src/map/map.cpp b/src/map/map.cpp index f4760b1b9..e7310db56 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -95,10 +95,6 @@ Map::Map(View& view_) async_terminate(new uv_async_t()), async_render(new uv_async_t()), async_cleanup(new uv_async_t()), - mutex_run(std::make_unique()), - cond_run(std::make_unique()), - mutex_pause(std::make_unique()), - cond_pause(std::make_unique()), view(view_), #ifndef NDEBUG main_thread(uv_thread_self()), @@ -228,19 +224,18 @@ void Map::stop(stop_callback cb, void *data) { void Map::pause(bool wait_for_pause) { assert(uv_thread_self() == main_thread); assert(async); - mutex_run->lock(); + mutex_run.lock(); pausing = true; - mutex_run->unlock(); + mutex_run.unlock(); uv_stop(**loop); rerender(); // Needed to ensure uv_stop is seen and uv_run exits, otherwise we deadlock on wait_for_pause if (wait_for_pause) { - mutex_pause->lock(); + std::unique_lock lock_pause (mutex_pause); while (!is_paused) { - cond_pause->wait(*mutex_pause); + cond_pause.wait(lock_pause); } - mutex_pause->unlock(); } } @@ -248,10 +243,10 @@ void Map::resume() { assert(uv_thread_self() == main_thread); assert(async); - mutex_run->lock(); + mutex_run.lock(); pausing = false; - cond_run->broadcast(); - mutex_run->unlock(); + cond_run.notify_all(); + mutex_run.unlock(); } void Map::run() { @@ -297,25 +292,23 @@ void Map::run() { } void Map::check_for_pause() { - mutex_run->lock(); + std::unique_lock lock_run (mutex_run); while (pausing) { view.make_inactive(); - mutex_pause->lock(); + mutex_pause.lock(); is_paused = true; - cond_pause->broadcast(); - mutex_pause->unlock(); + cond_pause.notify_all(); + mutex_pause.unlock(); - cond_run->wait(*mutex_run); + cond_run.wait(lock_run); view.make_active(); } - mutex_pause->lock(); + mutex_pause.lock(); is_paused = false; - mutex_pause->unlock(); - - mutex_run->unlock(); + mutex_pause.unlock(); } void Map::rerender() {