summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-09-16 18:23:42 +0200
committerKonstantin Käfer <mail@kkaefer.com>2014-09-24 16:14:09 +0200
commitfd2b2e208229259630f92bd7615f9197c163d27f (patch)
tree48cc7012e05c9c09e4bf437e0bab6598025e3f55 /include
parentf26bb724dc164b69b5358f30c6248fdf5cbd076b (diff)
downloadqtlocation-mapboxgl-fd2b2e208229259630f92bd7615f9197c163d27f.tar.gz
use separate workers for tile parsing to avoid blocking the threadpool for other libuv actions
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/map/map.hpp2
-rw-r--r--include/mbgl/util/uv-worker.h5
-rw-r--r--include/mbgl/util/uv.hpp1
-rw-r--r--include/mbgl/util/uv_detail.hpp35
4 files changed, 29 insertions, 14 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index 786c7196ae..c389d898b1 100644
--- a/include/mbgl/map/map.hpp
+++ b/include/mbgl/map/map.hpp
@@ -126,6 +126,7 @@ public:
util::ptr<Sprite> getSprite();
inline util::ptr<Texturepool> getTexturepool() { return texturepool; }
inline util::ptr<uv::loop> getLoop() { return loop; }
+ uv::worker &getWorker();
inline timestamp getAnimationTime() const { return animationTime; }
inline timestamp getTime() const { return animationTime; }
void updateTiles();
@@ -159,6 +160,7 @@ private:
private:
bool async = false;
util::ptr<uv::loop> loop;
+ std::unique_ptr<uv::worker> workers;
std::unique_ptr<uv::thread> thread;
std::unique_ptr<uv_async_t> async_terminate;
std::unique_ptr<uv_async_t> async_render;
diff --git a/include/mbgl/util/uv-worker.h b/include/mbgl/util/uv-worker.h
index b9eb10fb70..a66feb4d00 100644
--- a/include/mbgl/util/uv-worker.h
+++ b/include/mbgl/util/uv-worker.h
@@ -14,17 +14,16 @@ typedef struct uv_messenger_s uv_messenger_t;
typedef struct uv_worker_s uv_worker_t;
struct uv_worker_s {
- uv_thread_t thread;
uv_messenger_t *msgr;
uv_chan_t chan;
const char *name;
+ void *threads[2];
};
typedef void (*uv_worker_cb)(void *data);
typedef void (*uv_worker_after_cb)(void *data);
-int uv_worker_init(uv_worker_t *worker, uv_loop_t *loop);
-int uv_worker_init_named(uv_worker_t *worker, uv_loop_t *loop, const char *name);
+int uv_worker_init(uv_worker_t *worker, uv_loop_t *loop, int count, const char *name);
void uv_worker_send(uv_worker_t *worker, void *data, uv_worker_cb work_cb,
uv_worker_after_cb after_work_cb);
void uv_worker_close(uv_worker_t *worker);
diff --git a/include/mbgl/util/uv.hpp b/include/mbgl/util/uv.hpp
index 4ceb8b873f..80fff9c96f 100644
--- a/include/mbgl/util/uv.hpp
+++ b/include/mbgl/util/uv.hpp
@@ -14,6 +14,7 @@ std::string cwd();
class thread;
class rwlock;
class loop;
+class worker;
}
diff --git a/include/mbgl/util/uv_detail.hpp b/include/mbgl/util/uv_detail.hpp
index 272ca41495..b0b4fe583f 100644
--- a/include/mbgl/util/uv_detail.hpp
+++ b/include/mbgl/util/uv_detail.hpp
@@ -2,6 +2,7 @@
#define MBGL_UTIL_UV_DETAIL
#include <mbgl/util/ptr.hpp>
+#include <mbgl/util/uv-worker.h>
#include <uv.h>
@@ -108,6 +109,22 @@ private:
uv_once_t o = UV_ONCE_INIT;
};
+class worker {
+public:
+ inline worker(uv_loop_t *loop, unsigned int count, const char *name = nullptr) {
+ uv_worker_init(&w, loop, count, name);
+ }
+ inline ~worker() {
+ uv_worker_close(&w);
+ }
+ inline void add(void *data, uv_worker_cb work_cb, uv_worker_after_cb after_work_cb) {
+ uv_worker_send(&w, data, work_cb, after_work_cb);
+ }
+
+private:
+ uv_worker_t w;
+};
+
template <typename T>
class work {
public:
@@ -115,30 +132,26 @@ public:
typedef void (*after_work_callback)(T &object);
template<typename... Args>
- work(const mbgl::util::ptr<loop> &loop, work_callback work_cb, after_work_callback after_work_cb, Args&&... args)
- : loop(loop),
- data(std::forward<Args>(args)...),
+ work(worker &worker, work_callback work_cb, after_work_callback after_work_cb, Args&&... args)
+ : 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);
+ worker.add(this, do_work, after_work);
}
private:
- static void do_work(uv_work_t *req) {
- work<T> *w = static_cast<work<T> *>(req->data);
+ static void do_work(void *data) {
+ work<T> *w = reinterpret_cast<work<T> *>(data);
w->work_cb(w->data);
}
- static void after_work(uv_work_t *req, int) {
- work<T> *w = static_cast<work<T> *>(req->data);
+ static void after_work(void *data) {
+ work<T> *w = reinterpret_cast<work<T> *>(data);
w->after_work_cb(w->data);
delete w;
}
private:
- mbgl::util::ptr<uv::loop> loop;
- uv_work_t req;
T data;
work_callback work_cb;
after_work_callback after_work_cb;