diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2015-11-18 17:40:26 -0800 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2015-12-01 11:49:02 +0200 |
commit | 1c63f98f6df6a8b1a5db2cfb9e0d0bedba931b07 (patch) | |
tree | 2a0a38ce4f17d687ba093e880e8b34f06306e6f0 /platform | |
parent | f2553fff8926e78fdc00119efec48933f542ada1 (diff) | |
download | qtlocation-mapboxgl-1c63f98f6df6a8b1a5db2cfb9e0d0bedba931b07.tar.gz |
[core] Expose fewer RunLoop implementation details in header
Diffstat (limited to 'platform')
-rw-r--r-- | platform/default/http_request_curl.cpp | 2 | ||||
-rw-r--r-- | platform/default/run_loop.cpp | 22 |
2 files changed, 17 insertions, 7 deletions
diff --git a/platform/default/http_request_curl.cpp b/platform/default/http_request_curl.cpp index ad8e37bc2f..18d6d9d62a 100644 --- a/platform/default/http_request_curl.cpp +++ b/platform/default/http_request_curl.cpp @@ -9,9 +9,9 @@ #include <mbgl/util/run_loop.hpp> #include <mbgl/util/string.hpp> #include <mbgl/util/timer.hpp> +#include <mbgl/util/uv.hpp> #include <curl/curl.h> -#include <uv.h> #ifdef __ANDROID__ #include <mbgl/android/jni.hpp> diff --git a/platform/default/run_loop.cpp b/platform/default/run_loop.cpp index 7c3a74f2cb..a0262364ca 100644 --- a/platform/default/run_loop.cpp +++ b/platform/default/run_loop.cpp @@ -1,11 +1,15 @@ #include <mbgl/util/run_loop.hpp> - -#include <uv.h> +#include <mbgl/util/async_task.hpp> +#include <mbgl/util/uv.hpp> namespace mbgl { namespace util { -uv::tls<RunLoop> RunLoop::current; +static uv::tls<RunLoop> current; + +RunLoop* RunLoop::Get() { + return current.get(); +} class RunLoop::Impl { public: @@ -13,6 +17,7 @@ public: uv_loop_t *loop; RunLoop::Type type; + std::unique_ptr<AsyncTask> async; }; RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) { @@ -36,7 +41,7 @@ RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) { impl->type = type; current.set(this); - async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this)); + impl->async = std::make_unique<AsyncTask>(std::bind(&RunLoop::process, this)); } RunLoop::~RunLoop() { @@ -50,7 +55,7 @@ RunLoop::~RunLoop() { // close callbacks have been called. Not needed // for the default main loop because it is only // closed when the application exits. - async.reset(); + impl->async.reset(); runOnce(); #if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 @@ -67,6 +72,11 @@ LOOP_HANDLE RunLoop::getLoopHandle() { return current.get()->impl->loop; } +void RunLoop::push(std::shared_ptr<WorkTask> task) { + withMutex([&] { queue.push(task); }); + impl->async->send(); +} + void RunLoop::run() { uv_run(impl->loop, UV_RUN_DEFAULT); } @@ -76,7 +86,7 @@ void RunLoop::runOnce() { } void RunLoop::stop() { - invoke([&] { async->unref(); }); + invoke([&] { impl->async->unref(); }); } } |