diff options
author | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-02-18 01:09:48 +0200 |
---|---|---|
committer | Thiago Marcos P. Santos <thiago@mapbox.com> | 2016-02-20 13:33:13 +0200 |
commit | 8a53c1a881c6a5272b647ca267d40fbc435d11d9 (patch) | |
tree | e3b850b2cba09234e893dbc6e8260550528dede1 /platform/default/run_loop.cpp | |
parent | 1dbfbfe7e3dfa212fa8b63f1f31e2839341c745e (diff) | |
download | qtlocation-mapboxgl-8a53c1a881c6a5272b647ca267d40fbc435d11d9.tar.gz |
[core] libuv unref() not really needed
The run loop will be kept alive because it has an `AsyncTask`. We
also can simple stop the loop with `uv_stop()`.
The `RunLoop` is still gonna be the last object to be destroyed
because it is the first object to be created in the thread, so
by design it won't outlive `Timer`s and `AsyncTask`s.
This patch won't change the current behavior, will just make
the code simpler.
Diffstat (limited to 'platform/default/run_loop.cpp')
-rw-r--r-- | platform/default/run_loop.cpp | 29 |
1 files changed, 1 insertions, 28 deletions
diff --git a/platform/default/run_loop.cpp b/platform/default/run_loop.cpp index 76c01b80b7..b259fdfd21 100644 --- a/platform/default/run_loop.cpp +++ b/platform/default/run_loop.cpp @@ -13,12 +13,6 @@ namespace { using namespace mbgl::util; static ThreadLocal<RunLoop>& current = *new ThreadLocal<RunLoop>; -#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 -void dummyCallback(uv_async_t*, int) {}; -#else -void dummyCallback(uv_async_t*) {}; -#endif - } // namespace namespace mbgl { @@ -62,18 +56,7 @@ RunLoop* RunLoop::Get() { class RunLoop::Impl { public: - void closeHolder() { - uv_close(holderHandle(), [](uv_handle_t* h) { - delete reinterpret_cast<uv_async_t*>(h); - }); - } - - uv_handle_t* holderHandle() { - return reinterpret_cast<uv_handle_t*>(holder); - } - uv_loop_t *loop = nullptr; - uv_async_t* holder = new uv_async_t; RunLoop::Type type; std::unique_ptr<AsyncTask> async; @@ -99,12 +82,6 @@ RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) { break; } - // Just for holding a ref to the main loop and keep - // it alive as required by libuv. - if (uv_async_init(impl->loop, impl->holder, dummyCallback) != 0) { - throw std::runtime_error("Failed to initialize async."); - } - impl->type = type; current.set(this); @@ -114,10 +91,6 @@ RunLoop::RunLoop(Type type) : impl(std::make_unique<Impl>()) { RunLoop::~RunLoop() { current.set(nullptr); - // Close the dummy handle that we have - // just to keep the main loop alive. - impl->closeHolder(); - if (impl->type == Type::Default) { return; } @@ -161,7 +134,7 @@ void RunLoop::runOnce() { } void RunLoop::stop() { - invoke([&] { uv_unref(impl->holderHandle()); }); + invoke([&] { uv_stop(impl->loop); }); } void RunLoop::addWatch(int fd, Event event, std::function<void(int, Event)>&& callback) { |