summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2014-09-17 18:10:45 +0200
committerKonstantin Käfer <mail@kkaefer.com>2014-09-24 16:16:29 +0200
commitdaa22d6b0f0821465bf5adde9e09195bdaff30a7 (patch)
treee44bc31dcb1794c9db104b5717f69259e1b25ba5 /include
parent19129cbd023345569b24f1b9863e0ee32ae61182 (diff)
downloadqtlocation-mapboxgl-daa22d6b0f0821465bf5adde9e09195bdaff30a7.tar.gz
use asynchronous worker termination
instead of waiting until all threads have joined, we are now supplying a callback that will be invoked once all threads have terminated. you can use this callback to free the worker struct
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/util/uv-worker.h15
-rw-r--r--include/mbgl/util/uv_detail.hpp12
2 files changed, 17 insertions, 10 deletions
diff --git a/include/mbgl/util/uv-worker.h b/include/mbgl/util/uv-worker.h
index a66feb4d00..a9c9aff500 100644
--- a/include/mbgl/util/uv-worker.h
+++ b/include/mbgl/util/uv-worker.h
@@ -13,20 +13,25 @@ typedef struct uv_messenger_s uv_messenger_t;
typedef struct uv_worker_s uv_worker_t;
+typedef void (*uv_worker_cb)(void *data);
+typedef void (*uv_worker_after_cb)(void *data);
+typedef void (*uv_worker_close_cb)(uv_worker_t *worker);
+
struct uv_worker_s {
+#ifndef NDEBUG
+ unsigned long thread_id;
+#endif
uv_messenger_t *msgr;
uv_chan_t chan;
const char *name;
- void *threads[2];
+ int count;
+ uv_worker_close_cb close_cb;
};
-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 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);
+void uv_worker_close(uv_worker_t *worker, uv_worker_close_cb close_cb);
#ifdef __cplusplus
}
diff --git a/include/mbgl/util/uv_detail.hpp b/include/mbgl/util/uv_detail.hpp
index b0b4fe583f..e0a57ce65d 100644
--- a/include/mbgl/util/uv_detail.hpp
+++ b/include/mbgl/util/uv_detail.hpp
@@ -111,18 +111,20 @@ private:
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_loop_t *loop, unsigned int count, const char *name = nullptr) : w(new uv_worker_t) {
+ uv_worker_init(w, loop, count, name);
}
inline ~worker() {
- uv_worker_close(&w);
+ uv_worker_close(w, [](uv_worker_t *worker) {
+ delete worker;
+ });
}
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);
+ uv_worker_send(w, data, work_cb, after_work_cb);
}
private:
- uv_worker_t w;
+ uv_worker_t *w;
};
template <typename T>