summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2014-11-27 15:10:49 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2014-12-02 12:24:25 -0800
commit8f1772f18fe4ca74d66d351e3da2bf81b94c0330 (patch)
treefe09da030b641f13607474fb19ed1a46db2a4719 /include
parent9e819a4cbea3456f3293fdad4354d36e67d1cf22 (diff)
downloadqtlocation-mapboxgl-8f1772f18fe4ca74d66d351e3da2bf81b94c0330.tar.gz
More complete uv::thread
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/util/uv_detail.hpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/include/mbgl/util/uv_detail.hpp b/include/mbgl/util/uv_detail.hpp
index 7d9e657f5c..099e08d4f1 100644
--- a/include/mbgl/util/uv_detail.hpp
+++ b/include/mbgl/util/uv_detail.hpp
@@ -20,10 +20,26 @@ void close(T* handle) {
class thread : public mbgl::util::noncopyable {
public:
- inline operator uv_thread_t *() { return &t; }
+ inline thread(std::function<void ()> fn_)
+ : fn(fn_) {
+ if (uv_thread_create(&t, thread_cb, this) != 0) {
+ throw std::runtime_error("failed to initialize thread");
+ }
+ }
+
+ void join() {
+ if (uv_thread_join(&t) != 0) {
+ throw std::runtime_error("failed to join thred");
+ }
+ }
private:
+ static void thread_cb(void* data) {
+ reinterpret_cast<thread*>(data)->fn();
+ }
+
uv_thread_t t;
+ std::function<void ()> fn;
};
class loop : public mbgl::util::noncopyable {