diff options
author | Leith Bade <leith@mapbox.com> | 2014-12-04 22:19:46 +1100 |
---|---|---|
committer | Leith Bade <leith@mapbox.com> | 2014-12-04 22:19:46 +1100 |
commit | 8f1754cf0a7054dd1f6b16260eb99a2afd739f43 (patch) | |
tree | 9010e5835e263571b6b6732add21b51063cb0f81 /platform | |
parent | c817e476f3e2f424139dea968cb9747354bce1bc (diff) | |
parent | 57249ca32c7b0684be36f5195d4967e6517fe75b (diff) | |
download | qtlocation-mapboxgl-8f1754cf0a7054dd1f6b16260eb99a2afd739f43.tar.gz |
Merge branch 'master' of github.com:mapbox/mapbox-gl-native into android-mason
Conflicts:
include/mbgl/storage/base_request.hpp
include/mbgl/storage/file_request_baton.hpp
include/mbgl/storage/http_request.hpp
include/mbgl/storage/http_request_baton.hpp
include/mbgl/util/uv_detail.hpp
platform/darwin/http_request_baton_cocoa.mm
platform/default/caching_http_file_source.cpp
platform/default/http_request_baton_curl.cpp
src/map/map.cpp
src/storage/base_request.cpp
src/storage/file_request.cpp
src/storage/file_request_baton.cpp
src/storage/http_request.cpp
src/storage/http_request_baton.cpp
Diffstat (limited to 'platform')
-rw-r--r-- | platform/darwin/http_request_baton_cocoa.mm | 4 | ||||
-rw-r--r-- | platform/default/caching_http_file_source.cpp | 28 | ||||
-rw-r--r-- | platform/default/http_request_baton_curl.cpp | 15 |
3 files changed, 17 insertions, 30 deletions
diff --git a/platform/darwin/http_request_baton_cocoa.mm b/platform/darwin/http_request_baton_cocoa.mm index 4eea1d8f8b..472154dc2f 100644 --- a/platform/darwin/http_request_baton_cocoa.mm +++ b/platform/darwin/http_request_baton_cocoa.mm @@ -15,7 +15,7 @@ dispatch_once_t request_initialize = 0; NSURLSession *session = nullptr; void HTTPRequestBaton::start(const util::ptr<HTTPRequestBaton> &ptr) { - assert(uv_thread_self() == ptr->threadId); + assert(std::this_thread::get_id() == ptr->threadId); // Starts the request. util::ptr<HTTPRequestBaton> baton = ptr; @@ -131,7 +131,7 @@ void HTTPRequestBaton::start(const util::ptr<HTTPRequestBaton> &ptr) { } void HTTPRequestBaton::stop(const util::ptr<HTTPRequestBaton> &ptr) { - assert(uv_thread_self() == ptr->threadId); + assert(std::this_thread::get_id() == ptr->threadId); assert(ptr->ptr); NSURLSessionDataTask *task = CFBridgingRelease(ptr->ptr); diff --git a/platform/default/caching_http_file_source.cpp b/platform/default/caching_http_file_source.cpp index b7cbb268f4..20525a2647 100644 --- a/platform/default/caching_http_file_source.cpp +++ b/platform/default/caching_http_file_source.cpp @@ -10,27 +10,13 @@ namespace mbgl { -CachingHTTPFileSource::CachingHTTPFileSource(uv_loop_t* loop_, const std::string &path_) - : thread_id(uv_thread_self()), - path(path_), - store(!path.empty() ? util::ptr<SQLiteStore>(new SQLiteStore(loop_, path)) : nullptr), - loop(loop_), - queue(new uv_messenger_t) { - - uv_messenger_init(loop, queue, [](void *ptr) { - std::unique_ptr<std::function<void()>> fn { reinterpret_cast<std::function<void()> *>(ptr) }; - (*fn)(); - }); - uv_unref((uv_handle_t *)&queue->async); -} - CachingHTTPFileSource::CachingHTTPFileSource(const std::string &path_) : path(path_) {} CachingHTTPFileSource::~CachingHTTPFileSource() { if (hasLoop()) { // FIXME temp fix for #608 crash - // assert(thread_id == uv_thread_self()); + // assert(thread_id == std::this_thread::get_id()); uv_messenger_stop(queue, [](uv_messenger_t *msgr) { delete msgr; }); @@ -47,7 +33,7 @@ CachingHTTPFileSource::~CachingHTTPFileSource() { } void CachingHTTPFileSource::setLoop(uv_loop_t* loop_) { - thread_id = uv_thread_self(); + thread_id = std::this_thread::get_id(); store = !path.empty() ? util::ptr<SQLiteStore>(new SQLiteStore(loop_, path)) : nullptr; loop = loop_; queue = new uv_messenger_t; @@ -64,17 +50,17 @@ bool CachingHTTPFileSource::hasLoop() { } void CachingHTTPFileSource::setBase(const std::string &value) { - assert(thread_id == uv_thread_self()); + assert(thread_id == std::this_thread::get_id()); base = value; } const std::string &CachingHTTPFileSource::getBase() const { - assert(thread_id == uv_thread_self()); + assert(thread_id == std::this_thread::get_id()); return base; } std::unique_ptr<Request> CachingHTTPFileSource::request(ResourceType type, const std::string &url) { - assert(thread_id == uv_thread_self()); + assert(thread_id == std::this_thread::get_id()); // Make URL absolute. const std::string absoluteURL = [&]() -> std::string { @@ -111,7 +97,7 @@ std::unique_ptr<Request> CachingHTTPFileSource::request(ResourceType type, const } void CachingHTTPFileSource::prepare(std::function<void()> fn) { - if (thread_id == uv_thread_self()) { + if (thread_id == std::this_thread::get_id()) { fn(); } else { uv_messenger_send(queue, new std::function<void()>(std::move(fn))); @@ -119,7 +105,7 @@ void CachingHTTPFileSource::prepare(std::function<void()> fn) { } void CachingHTTPFileSource::retryAllPending() { - assert(thread_id == uv_thread_self()); + assert(thread_id == std::this_thread::get_id()); util::ptr<BaseRequest> req; for (const std::pair<std::string, std::weak_ptr<BaseRequest>> &pair : pending) { diff --git a/platform/default/http_request_baton_curl.cpp b/platform/default/http_request_baton_curl.cpp index 5578a69041..74c6187e76 100644 --- a/platform/default/http_request_baton_curl.cpp +++ b/platform/default/http_request_baton_curl.cpp @@ -17,6 +17,7 @@ #include <queue> #include <cassert> #include <cstring> +#include <thread> // Check curl library version. @@ -76,7 +77,7 @@ static uv_loop_t *loop = nullptr; static uv_messenger_t start_messenger; static uv_messenger_t stop_messenger; static uv_thread_t thread; -static unsigned long thread_id; +static std::thread::id thread_id; // Used as the CURL timer function to periodically check for socket updates. static uv_timer_t timeout; @@ -321,7 +322,7 @@ void thread_init(void *) { #ifdef __APPLE__ pthread_setname_np("CURL"); #endif - thread_id = uv_thread_self(); + thread_id = std::this_thread::get_id(); if (curl_global_init(CURL_GLOBAL_ALL)) { throw std::runtime_error("Could not init cURL"); @@ -363,7 +364,7 @@ void thread_init(void *) { curl_share_cleanup(share); share = nullptr; - thread_id = -1; + thread_id = std::thread::id(); } // This function is called when we have new data for a request. We just append it to the string @@ -510,7 +511,7 @@ static CURLcode sslctx_function(CURL */*curl*/, void *sslctx, void */*parm*/) { // This function must run in the CURL thread. void start_request(void *const ptr) { - assert(uv_thread_self() == thread_id); + assert(std::this_thread::get_id() == thread_id); // The Context object stores information that we need to retain throughout the request, such // as the actual CURL easy handle, the baton, and the list of headers. The Context itself is @@ -559,7 +560,7 @@ void start_request(void *const ptr) { // This function must run in the CURL thread. void stop_request(void *const ptr) { - assert(uv_thread_self() == thread_id); + assert(std::this_thread::get_id() == thread_id); auto baton = *(util::ptr<HTTPRequestBaton> *)ptr; delete (util::ptr<HTTPRequestBaton> *)ptr; assert(baton); @@ -595,14 +596,14 @@ void create_thread() { // This function must be run from the main thread (== where the HTTPRequestBaton was created) void HTTPRequestBaton::start(const util::ptr<HTTPRequestBaton> &ptr) { - assert(uv_thread_self() == ptr->threadId); + assert(std::this_thread::get_id() == ptr->threadId); uv_once(&once, create_thread); uv_messenger_send(&start_messenger, new util::ptr<HTTPRequestBaton>(ptr)); } // This function must be run from the main thread (== where the HTTPRequestBaton was created) void HTTPRequestBaton::stop(const util::ptr<HTTPRequestBaton> &ptr) { - assert(uv_thread_self() == ptr->threadId); + assert(std::this_thread::get_id() == ptr->threadId); uv_once(&once, create_thread); uv_messenger_send(&stop_messenger, new util::ptr<HTTPRequestBaton>(ptr)); } |