summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-08-12 11:45:30 +0200
committerKonstantin Käfer <mail@kkaefer.com>2014-08-12 11:45:30 +0200
commit6f802642917136eb29d385d31d1817a98b562bbe (patch)
treebbccd9517e1fb430711440077b5c673f31ab3d2a /include
parente4c311a864d522e402b67f5393f57d0f663330e4 (diff)
downloadqtlocation-mapboxgl-6f802642917136eb29d385d31d1817a98b562bbe.tar.gz
remove uv.h dependency from header files
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/map/map.hpp2
-rw-r--r--include/mbgl/map/transform.hpp2
-rw-r--r--include/mbgl/platform/platform.hpp8
-rw-r--r--include/mbgl/platform/request.hpp9
-rw-r--r--include/mbgl/style/style.hpp2
-rw-r--r--include/mbgl/util/filesource.hpp6
-rw-r--r--include/mbgl/util/uv.hpp154
-rw-r--r--include/mbgl/util/uv_detail.hpp158
8 files changed, 173 insertions, 168 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index be01b456cc..554962c713 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -156,7 +156,7 @@ private:
private:
bool async = false;
std::shared_ptr<uv::loop> loop;
- uv_thread_t thread;
+ std::unique_ptr<uv::thread> thread;
uv_async_t *async_terminate = nullptr;
uv_async_t *async_render = nullptr;
uv_async_t *async_cleanup = nullptr;
diff --git a/include/mbgl/map/transform.hpp b/include/mbgl/map/transform.hpp
index df7839ea96..d0f56b7fba 100644
--- a/include/mbgl/map/transform.hpp
+++ b/include/mbgl/map/transform.hpp
@@ -80,7 +80,7 @@ private:
private:
View &view;
- mutable uv::rwlock mtx;
+ std::unique_ptr<uv::rwlock> mtx;
// This reflects the current state of the transform, representing the actual position of the
// map. After calling a transform function with a timer, this will likely remain the same until
diff --git a/include/mbgl/platform/platform.hpp b/include/mbgl/platform/platform.hpp
index 02aeb594b6..43c6ce4f5e 100644
--- a/include/mbgl/platform/platform.hpp
+++ b/include/mbgl/platform/platform.hpp
@@ -1,16 +1,12 @@
#ifndef MBGL_PLATFORM_PLATFORM
#define MBGL_PLATFORM_PLATFORM
+#include <mbgl/util/uv.hpp>
+
#include <memory>
#include <functional>
#include <string>
-typedef struct uv_loop_s uv_loop_t;
-
-namespace uv {
-class loop;
-}
-
namespace mbgl {
namespace platform {
diff --git a/include/mbgl/platform/request.hpp b/include/mbgl/platform/request.hpp
index 7d2da8888c..0cbacf645d 100644
--- a/include/mbgl/platform/request.hpp
+++ b/include/mbgl/platform/request.hpp
@@ -7,14 +7,7 @@
#include <atomic>
#include <mbgl/util/noncopyable.hpp>
-
-// Forward definition.
-typedef struct uv_loop_s uv_loop_t;
-typedef struct uv_async_s uv_async_t;
-
-namespace uv {
-class loop;
-}
+#include <mbgl/util/uv.hpp>
namespace mbgl {
namespace platform {
diff --git a/include/mbgl/style/style.hpp b/include/mbgl/style/style.hpp
index 3df58ab42b..1f24674e42 100644
--- a/include/mbgl/style/style.hpp
+++ b/include/mbgl/style/style.hpp
@@ -62,7 +62,7 @@ private:
PropertyTransition defaultTransition;
bool initial_render_complete = false;
- mutable uv::rwlock mtx;
+ std::unique_ptr<uv::rwlock> mtx;
};
}
diff --git a/include/mbgl/util/filesource.hpp b/include/mbgl/util/filesource.hpp
index 0d339cbac7..18c63ddfeb 100644
--- a/include/mbgl/util/filesource.hpp
+++ b/include/mbgl/util/filesource.hpp
@@ -1,14 +1,12 @@
#ifndef MBGL_UTIL_FILESOURCE
#define MBGL_UTIL_FILESOURCE
+#include <mbgl/util/uv.hpp>
+
#include <string>
#include <memory>
#include <functional>
-namespace uv {
-class loop;
-}
-
namespace mbgl {
namespace platform {
diff --git a/include/mbgl/util/uv.hpp b/include/mbgl/util/uv.hpp
index 518e007afe..4ceb8b873f 100644
--- a/include/mbgl/util/uv.hpp
+++ b/include/mbgl/util/uv.hpp
@@ -1,159 +1,19 @@
#ifndef MBGL_UTIL_UV
#define MBGL_UTIL_UV
-#include <uv.h>
-#include <functional>
-#include <cassert>
-
-#ifdef __clang__
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wunused-parameter"
-#endif
-
-#include <boost/lockfree/queue.hpp>
-
-#ifdef __clang__
-#pragma clang diagnostic pop
-#endif
-
#include <string>
+typedef struct uv_async_s uv_async_t;
+typedef struct uv_handle_s uv_handle_t;
+typedef struct uv_loop_s uv_loop_t;
namespace uv {
-inline std::string cwd() {
- size_t max = 0;
- std::string dir;
- do {
- max += 256;
- dir.resize(max);
- uv_cwd(const_cast<char *>(dir.data()), &max);
- } while (max == dir.size());
- dir.resize(max - 1);
- return dir;
-}
-
-class loop {
-public:
- inline loop() {
- if (uv_loop_init(&l) != 0) {
- throw std::runtime_error("failed to initialize loop");
- }
- }
-
- inline ~loop() { uv_loop_close(&l); }
-
- inline uv_loop_t *operator*() { return &l; }
-
-private:
- uv_loop_t l;
-};
-
-class mutex {
-public:
- inline mutex() {
- if (uv_mutex_init(&mtx) != 0) {
- throw std::runtime_error("failed to initialize mutex");
- }
- }
- inline ~mutex() { uv_mutex_destroy(&mtx); }
- inline void lock() { uv_mutex_lock(&mtx); }
- inline void unlock() { uv_mutex_unlock(&mtx); }
-
-private:
- uv_mutex_t mtx;
-};
-
-class lock {
-public:
- lock(mutex &mtx) : mtx(mtx) { mtx.lock(); }
- ~lock() { mtx.unlock(); }
-
-private:
- mutex &mtx;
-};
-
-class rwlock {
-public:
- inline rwlock() {
- if (uv_rwlock_init(&mtx) != 0) {
- throw std::runtime_error("failed to initialize read-write lock");
- }
- }
- inline ~rwlock() { uv_rwlock_destroy(&mtx); }
- inline void rdlock() { uv_rwlock_rdlock(&mtx); }
- inline void wrlock() { uv_rwlock_wrlock(&mtx); }
- inline void rdunlock() { uv_rwlock_rdunlock(&mtx); }
- inline void wrunlock() { uv_rwlock_wrunlock(&mtx); }
-
-private:
- uv_rwlock_t mtx;
-};
-
-class readlock {
-public:
- inline readlock(rwlock &mtx) : mtx(mtx) { mtx.rdlock(); }
- inline ~readlock() { mtx.rdunlock(); }
-
-private:
- rwlock &mtx;
-};
-
-class writelock {
-public:
- inline writelock(rwlock &mtx) : mtx(mtx) { mtx.wrlock(); }
- inline ~writelock() { mtx.wrunlock(); }
-
-private:
- rwlock &mtx;
-};
-
-class once {
-public:
- typedef void (*callback)();
- void operator()(void (*callback)(void)) {
- uv_once(&o, callback);
- }
-
-private:
- uv_once_t o = UV_ONCE_INIT;
-};
-
-template <typename T>
-class work {
-public:
- typedef void (*work_callback)(T &object);
- typedef void (*after_work_callback)(T &object);
-
- template<typename... Args>
- work(const std::shared_ptr<loop> &loop, work_callback work_cb, after_work_callback after_work_cb, Args&&... args)
- : loop(loop),
- data(std::forward<Args>(args)...),
- work_cb(work_cb),
- after_work_cb(after_work_cb) {
- req.data = this;
- uv_queue_work(**loop, &req, do_work, after_work);
- }
-
-private:
- static void do_work(uv_work_t *req) {
- work<T> *w = static_cast<work<T> *>(req->data);
- w->work_cb(w->data);
- }
-
- static void after_work(uv_work_t *req, int) {
- work<T> *w = static_cast<work<T> *>(req->data);
- w->after_work_cb(w->data);
- delete w;
- }
+std::string cwd();
-private:
- std::shared_ptr<uv::loop> loop;
- uv_work_t req;
- T data;
- work_callback work_cb;
- after_work_callback after_work_cb;
-};
+class thread;
+class rwlock;
+class loop;
}
diff --git a/include/mbgl/util/uv_detail.hpp b/include/mbgl/util/uv_detail.hpp
new file mode 100644
index 0000000000..c65c247ba1
--- /dev/null
+++ b/include/mbgl/util/uv_detail.hpp
@@ -0,0 +1,158 @@
+#ifndef MBGL_UTIL_UV_DETAIL
+#define MBGL_UTIL_UV_DETAIL
+
+#include <uv.h>
+#include <functional>
+#include <cassert>
+
+#ifdef __clang__
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wunused-parameter"
+#endif
+
+#include <boost/lockfree/queue.hpp>
+
+#ifdef __clang__
+#pragma clang diagnostic pop
+#endif
+
+#include <string>
+
+
+namespace uv {
+
+class thread {
+public:
+ inline operator uv_thread_t *() { return &t; }
+
+private:
+ uv_thread_t t;
+};
+
+class loop {
+public:
+ inline loop() {
+ if (uv_loop_init(&l) != 0) {
+ throw std::runtime_error("failed to initialize loop");
+ }
+ }
+
+ inline ~loop() { uv_loop_close(&l); }
+
+ inline uv_loop_t *operator*() { return &l; }
+
+private:
+ uv_loop_t l;
+};
+
+class mutex {
+public:
+ inline mutex() {
+ if (uv_mutex_init(&mtx) != 0) {
+ throw std::runtime_error("failed to initialize mutex");
+ }
+ }
+ inline ~mutex() { uv_mutex_destroy(&mtx); }
+ inline void lock() { uv_mutex_lock(&mtx); }
+ inline void unlock() { uv_mutex_unlock(&mtx); }
+
+private:
+ uv_mutex_t mtx;
+};
+
+class lock {
+public:
+ lock(mutex &mtx) : mtx(mtx) { mtx.lock(); }
+ ~lock() { mtx.unlock(); }
+
+private:
+ mutex &mtx;
+};
+
+class rwlock {
+public:
+ inline rwlock() {
+ if (uv_rwlock_init(&mtx) != 0) {
+ throw std::runtime_error("failed to initialize read-write lock");
+ }
+ }
+ inline ~rwlock() { uv_rwlock_destroy(&mtx); }
+ inline void rdlock() { uv_rwlock_rdlock(&mtx); }
+ inline void wrlock() { uv_rwlock_wrlock(&mtx); }
+ inline void rdunlock() { uv_rwlock_rdunlock(&mtx); }
+ inline void wrunlock() { uv_rwlock_wrunlock(&mtx); }
+
+private:
+ uv_rwlock_t mtx;
+};
+
+class readlock {
+public:
+ inline readlock(rwlock &mtx) : mtx(mtx) { mtx.rdlock(); }
+ inline readlock(const std::unique_ptr<rwlock> &mtx) : mtx(*mtx) { mtx->rdlock(); }
+ inline ~readlock() { mtx.rdunlock(); }
+
+private:
+ rwlock &mtx;
+};
+
+class writelock {
+public:
+ inline writelock(rwlock &mtx) : mtx(mtx) { mtx.wrlock(); }
+ inline writelock(const std::unique_ptr<rwlock> &mtx) : mtx(*mtx) { mtx->wrlock(); }
+ inline ~writelock() { mtx.wrunlock(); }
+
+private:
+ rwlock &mtx;
+};
+
+class once {
+public:
+ typedef void (*callback)();
+ void operator()(void (*callback)(void)) {
+ uv_once(&o, callback);
+ }
+
+private:
+ uv_once_t o = UV_ONCE_INIT;
+};
+
+template <typename T>
+class work {
+public:
+ typedef void (*work_callback)(T &object);
+ typedef void (*after_work_callback)(T &object);
+
+ template<typename... Args>
+ work(const std::shared_ptr<loop> &loop, work_callback work_cb, after_work_callback after_work_cb, Args&&... args)
+ : loop(loop),
+ data(std::forward<Args>(args)...),
+ work_cb(work_cb),
+ after_work_cb(after_work_cb) {
+ req.data = this;
+ uv_queue_work(**loop, &req, do_work, after_work);
+ }
+
+private:
+ static void do_work(uv_work_t *req) {
+ work<T> *w = static_cast<work<T> *>(req->data);
+ w->work_cb(w->data);
+ }
+
+ static void after_work(uv_work_t *req, int) {
+ work<T> *w = static_cast<work<T> *>(req->data);
+ w->after_work_cb(w->data);
+ delete w;
+ }
+
+private:
+ std::shared_ptr<uv::loop> loop;
+ uv_work_t req;
+ T data;
+ work_callback work_cb;
+ after_work_callback after_work_cb;
+};
+
+}
+
+#endif