diff options
author | Leith Bade <leith@mapbox.com> | 2014-12-04 08:02:57 +1100 |
---|---|---|
committer | Leith Bade <leith@mapbox.com> | 2014-12-04 08:02:57 +1100 |
commit | 991a74774e1e835ff2277b3997d60f09245593dd (patch) | |
tree | f881149caec5f1e1a55a4e9900548f8a5e92bf0b /include/mbgl/util | |
parent | 58833dd56a29d14afb7b40d8484328941d3d5020 (diff) | |
parent | 21b4f8c501d67ed8ecf6dedbdd55064a5c8f823c (diff) | |
download | qtlocation-mapboxgl-991a74774e1e835ff2277b3997d60f09245593dd.tar.gz |
Merge branch 'master' of github.com:mapbox/mapbox-gl-native into android-mason
Conflicts:
gyp/mbgl-ios.gypi
gyp/mbgl-linux.gypi
gyp/mbgl-osx.gypi
platform/default/caching_http_file_source.cpp
Diffstat (limited to 'include/mbgl/util')
-rw-r--r-- | include/mbgl/util/uv_detail.hpp | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/include/mbgl/util/uv_detail.hpp b/include/mbgl/util/uv_detail.hpp index 61a972c44f..055993db3e 100644 --- a/include/mbgl/util/uv_detail.hpp +++ b/include/mbgl/util/uv_detail.hpp @@ -14,8 +14,10 @@ namespace uv { template <class T> -void close(T* handle) { - uv_close(reinterpret_cast<uv_handle_t*>(handle), nullptr); +void close(std::unique_ptr<T> ptr) { + uv_close(reinterpret_cast<uv_handle_t*>(ptr.release()), [](uv_handle_t* handle) { + delete reinterpret_cast<T*>(handle); + }); } class thread : public mbgl::util::noncopyable { @@ -75,19 +77,21 @@ private: class async : public mbgl::util::noncopyable { public: inline async(uv_loop_t* loop, std::function<void ()> fn_) - : fn(fn_) { - a.data = this; - if (uv_async_init(loop, &a, async_cb) != 0) { + : a(new uv_async_t) + , fn(fn_) + { + a->data = this; + if (uv_async_init(loop, a.get(), async_cb) != 0) { throw std::runtime_error("failed to initialize async"); } } inline ~async() { - close(&a); + close(std::move(a)); } inline void send() { - if (uv_async_send(&a) != 0) { + if (uv_async_send(a.get()) != 0) { throw std::runtime_error("failed to async send"); } } @@ -101,7 +105,7 @@ private: reinterpret_cast<async*>(a->data)->fn(); } - uv_async_t a; + std::unique_ptr<uv_async_t> a; std::function<void ()> fn; }; |