summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2014-12-03 17:02:38 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2014-12-03 17:38:10 -0800
commit57249ca32c7b0684be36f5195d4967e6517fe75b (patch)
tree9315b1cd1fa25fe0eee1b09c651a6a1cf433ad39 /platform
parent10ebcbca93327e098a48d88869b6d8a2a19df6da (diff)
downloadqtlocation-mapboxgl-57249ca32c7b0684be36f5195d4967e6517fe75b.tar.gz
Prefer stdlib to libuv (fixes #688)
Diffstat (limited to 'platform')
-rw-r--r--platform/darwin/http_request_baton_cocoa.mm4
-rw-r--r--platform/default/caching_http_file_source.cpp14
-rw-r--r--platform/default/http_request_baton_curl.cpp15
3 files changed, 17 insertions, 16 deletions
diff --git a/platform/darwin/http_request_baton_cocoa.mm b/platform/darwin/http_request_baton_cocoa.mm
index 28afbb5086..1c256d0ba8 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->thread_id);
+ assert(std::this_thread::get_id() == ptr->thread_id);
// 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->thread_id);
+ assert(std::this_thread::get_id() == ptr->thread_id);
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 4ea85dd2c4..3e74f5ed05 100644
--- a/platform/default/caching_http_file_source.cpp
+++ b/platform/default/caching_http_file_source.cpp
@@ -14,7 +14,7 @@ CachingHTTPFileSource::CachingHTTPFileSource(const std::string &path_)
CachingHTTPFileSource::~CachingHTTPFileSource() {
if (hasLoop()) {
- assert(thread_id == uv_thread_self());
+ assert(thread_id == std::this_thread::get_id());
uv_messenger_stop(queue, [](uv_messenger_t *msgr) {
delete msgr;
});
@@ -31,7 +31,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;
@@ -48,17 +48,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 {
@@ -93,7 +93,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)));
@@ -101,7 +101,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 4b825622ae..f05ee5acf9 100644
--- a/platform/default/http_request_baton_curl.cpp
+++ b/platform/default/http_request_baton_curl.cpp
@@ -10,6 +10,7 @@
#include <queue>
#include <cassert>
#include <cstring>
+#include <thread>
// Check curl library version.
@@ -69,7 +70,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;
@@ -314,7 +315,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");
@@ -356,7 +357,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
@@ -406,7 +407,7 @@ size_t curl_header_cb(char * const buffer, const size_t size, const size_t nmemb
// 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
@@ -451,7 +452,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);
@@ -487,14 +488,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->thread_id);
+ assert(std::this_thread::get_id() == ptr->thread_id);
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->thread_id);
+ assert(std::this_thread::get_id() == ptr->thread_id);
uv_once(&once, create_thread);
uv_messenger_send(&stop_messenger, new util::ptr<HTTPRequestBaton>(ptr));
}