diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2014-12-03 17:02:38 -0800 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2014-12-03 17:38:10 -0800 |
commit | 57249ca32c7b0684be36f5195d4967e6517fe75b (patch) | |
tree | 9315b1cd1fa25fe0eee1b09c651a6a1cf433ad39 /include | |
parent | 10ebcbca93327e098a48d88869b6d8a2a19df6da (diff) | |
download | qtlocation-mapboxgl-57249ca32c7b0684be36f5195d4967e6517fe75b.tar.gz |
Prefer stdlib to libuv (fixes #688)
Diffstat (limited to 'include')
-rw-r--r-- | include/mbgl/map/map.hpp | 8 | ||||
-rw-r--r-- | include/mbgl/platform/default/caching_http_file_source.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/storage/base_request.hpp | 4 | ||||
-rw-r--r-- | include/mbgl/storage/file_request_baton.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/storage/http_request.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/storage/http_request_baton.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/storage/request.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/storage/sqlite_store.hpp | 3 | ||||
-rw-r--r-- | include/mbgl/util/uv.hpp | 1 | ||||
-rw-r--r-- | include/mbgl/util/uv_detail.hpp | 48 |
10 files changed, 19 insertions, 60 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 718efbf149..4e6eef89cf 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -9,8 +9,10 @@ #include <mbgl/util/time.hpp> #include <mbgl/util/uv.hpp> #include <mbgl/util/ptr.hpp> + #include <cstdint> #include <atomic> +#include <thread> #include <iosfwd> #include <set> #include <vector> @@ -147,7 +149,7 @@ private: bool async = false; std::unique_ptr<uv::loop> loop; std::unique_ptr<uv::worker> workers; - std::unique_ptr<uv::thread> thread; + std::thread thread; std::unique_ptr<uv::async> asyncTerminate; std::unique_ptr<uv::async> asyncRender; std::unique_ptr<uv::async> asyncCleanup; @@ -170,8 +172,8 @@ private: View &view; #ifndef NDEBUG - const unsigned long mainThread; - unsigned long mapThread = -1; + const std::thread::id mainThread; + std::thread::id mapThread; #endif Transform transform; diff --git a/include/mbgl/platform/default/caching_http_file_source.hpp b/include/mbgl/platform/default/caching_http_file_source.hpp index fe6972230f..c394474881 100644 --- a/include/mbgl/platform/default/caching_http_file_source.hpp +++ b/include/mbgl/platform/default/caching_http_file_source.hpp @@ -3,6 +3,7 @@ #include <mbgl/storage/file_source.hpp> +#include <thread> #include <unordered_map> typedef struct uv_messenger_s uv_messenger_t; @@ -32,7 +33,7 @@ public: void retryAllPending(); private: - unsigned long thread_id; + std::thread::id thread_id; // Path to the cache database. std::string path; diff --git a/include/mbgl/storage/base_request.hpp b/include/mbgl/storage/base_request.hpp index 16ff24faa3..2913c5eae5 100644 --- a/include/mbgl/storage/base_request.hpp +++ b/include/mbgl/storage/base_request.hpp @@ -7,7 +7,7 @@ #include <string> #include <forward_list> #include <functional> - +#include <thread> typedef struct uv_loop_s uv_loop_t; typedef struct uv_async_s uv_async_t; @@ -46,7 +46,7 @@ public: virtual void retryImmediately(); public: - const unsigned long thread_id; + const std::thread::id thread_id; const std::string path; std::unique_ptr<Response> response; diff --git a/include/mbgl/storage/file_request_baton.hpp b/include/mbgl/storage/file_request_baton.hpp index 0f1968ca13..897c88061d 100644 --- a/include/mbgl/storage/file_request_baton.hpp +++ b/include/mbgl/storage/file_request_baton.hpp @@ -2,6 +2,7 @@ #define MBGL_STORAGE_FILE_REQUEST_BATON #include <mbgl/storage/file_request.hpp> +#include <thread> #include <uv.h> @@ -19,7 +20,7 @@ struct FileRequestBaton { static void notify_error(uv_fs_t *req); static void cleanup(uv_fs_t *req); - const unsigned long thread_id; + const std::thread::id thread_id; FileRequest *request = nullptr; uv_fs_t req; uv_file fd = -1; diff --git a/include/mbgl/storage/http_request.hpp b/include/mbgl/storage/http_request.hpp index ec76f1147c..71d6e8814c 100644 --- a/include/mbgl/storage/http_request.hpp +++ b/include/mbgl/storage/http_request.hpp @@ -8,6 +8,7 @@ #include <string> #include <memory> #include <cassert> +#include <thread> typedef struct uv_loop_s uv_loop_t; typedef struct uv_timer_s uv_timer_t; @@ -40,7 +41,7 @@ private: void removeBackoffTimer(); private: - const unsigned long thread_id; + const std::thread::id thread_id; uv_loop_t *const loop; CacheRequestBaton *cache_baton = nullptr; util::ptr<HTTPRequestBaton> http_baton; diff --git a/include/mbgl/storage/http_request_baton.hpp b/include/mbgl/storage/http_request_baton.hpp index 279784ec25..545f9e236c 100644 --- a/include/mbgl/storage/http_request_baton.hpp +++ b/include/mbgl/storage/http_request_baton.hpp @@ -5,6 +5,7 @@ #include <mbgl/util/ptr.hpp> #include <string> +#include <thread> typedef struct uv_async_s uv_async_t; @@ -47,7 +48,7 @@ struct HTTPRequestBaton { HTTPRequestBaton(const std::string &path); ~HTTPRequestBaton(); - const unsigned long thread_id; + const std::thread::id thread_id; const std::string path; HTTPRequest *request = nullptr; diff --git a/include/mbgl/storage/request.hpp b/include/mbgl/storage/request.hpp index e603ee527a..11b5541d18 100644 --- a/include/mbgl/storage/request.hpp +++ b/include/mbgl/storage/request.hpp @@ -5,6 +5,7 @@ #include <mbgl/storage/response.hpp> #include <mbgl/util/ptr.hpp> +#include <thread> #include <forward_list> typedef struct uv_loop_s uv_loop_t; @@ -29,7 +30,7 @@ public: void cancel(); private: - const unsigned long thread_id; + const std::thread::id thread_id; util::ptr<BaseRequest> base; std::forward_list<Callback *> callbacks; }; diff --git a/include/mbgl/storage/sqlite_store.hpp b/include/mbgl/storage/sqlite_store.hpp index cb7730d0bf..a691b474e0 100644 --- a/include/mbgl/storage/sqlite_store.hpp +++ b/include/mbgl/storage/sqlite_store.hpp @@ -7,6 +7,7 @@ #include <uv.h> #include <string> +#include <thread> typedef struct uv_worker_s uv_worker_t; @@ -37,7 +38,7 @@ private: static void deliverResult(uv_work_t *req, int status); private: - const unsigned long thread_id; + const std::thread::id thread_id; util::ptr<mapbox::sqlite::Database> db; uv_worker_t *worker = nullptr; }; diff --git a/include/mbgl/util/uv.hpp b/include/mbgl/util/uv.hpp index 2fc3e0dc30..74ed9c87a8 100644 --- a/include/mbgl/util/uv.hpp +++ b/include/mbgl/util/uv.hpp @@ -12,7 +12,6 @@ namespace uv { std::string cwd(); -class thread; class rwlock; class loop; class async; diff --git a/include/mbgl/util/uv_detail.hpp b/include/mbgl/util/uv_detail.hpp index b6b9be208d..99f5edc145 100644 --- a/include/mbgl/util/uv_detail.hpp +++ b/include/mbgl/util/uv_detail.hpp @@ -20,30 +20,6 @@ void close(std::unique_ptr<T> ptr) { }); } -class thread : public mbgl::util::noncopyable { -public: - 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 { public: inline loop() { @@ -109,30 +85,6 @@ private: std::function<void ()> fn; }; -class mutex : public mbgl::util::noncopyable { -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 mbgl::util::noncopyable { -public: - lock(mutex &mtx_) : mtx(mtx_) { mtx.lock(); } - ~lock() { mtx.unlock(); } - -private: - mutex &mtx; -}; - class rwlock : public mbgl::util::noncopyable { public: inline rwlock() { |