summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeith Bade <leith@mapbox.com>2014-12-04 22:19:46 +1100
committerLeith Bade <leith@mapbox.com>2014-12-04 22:19:46 +1100
commit8f1754cf0a7054dd1f6b16260eb99a2afd739f43 (patch)
tree9010e5835e263571b6b6732add21b51063cb0f81
parentc817e476f3e2f424139dea968cb9747354bce1bc (diff)
parent57249ca32c7b0684be36f5195d4967e6517fe75b (diff)
downloadqtlocation-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
-rw-r--r--include/mbgl/map/map.hpp8
-rw-r--r--include/mbgl/platform/default/caching_http_file_source.hpp4
-rw-r--r--include/mbgl/storage/base_request.hpp4
-rw-r--r--include/mbgl/storage/file_request_baton.hpp3
-rw-r--r--include/mbgl/storage/http_request.hpp3
-rw-r--r--include/mbgl/storage/http_request_baton.hpp3
-rw-r--r--include/mbgl/storage/request.hpp3
-rw-r--r--include/mbgl/storage/sqlite_store.hpp3
-rw-r--r--include/mbgl/util/uv.hpp1
-rw-r--r--include/mbgl/util/uv_detail.hpp67
-rw-r--r--platform/darwin/http_request_baton_cocoa.mm4
-rw-r--r--platform/default/caching_http_file_source.cpp28
-rw-r--r--platform/default/http_request_baton_curl.cpp15
-rw-r--r--src/map/map.cpp29
-rw-r--r--src/storage/base_request.cpp10
-rw-r--r--src/storage/file_request.cpp4
-rw-r--r--src/storage/file_request_baton.cpp14
-rw-r--r--src/storage/http_request.cpp55
-rw-r--r--src/storage/http_request_baton.cpp4
-rw-r--r--src/storage/request.cpp10
-rw-r--r--src/storage/sqlite_store.cpp8
21 files changed, 135 insertions, 145 deletions
diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp
index f222036bfa..91205f03c6 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>
@@ -159,7 +161,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;
@@ -190,8 +192,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 058bdc7c3e..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;
@@ -14,7 +15,6 @@ class SQLiteStore;
class CachingHTTPFileSource : public FileSource {
public:
- CachingHTTPFileSource(uv_loop_t*, const std::string &path_);
CachingHTTPFileSource(const std::string &path_);
~CachingHTTPFileSource();
@@ -33,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 82372416dc..5119c343e9 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 threadId;
+ const std::thread::id threadId;
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 1283038dd5..0c3fa16da3 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 threadId;
+ const std::thread::id threadId;
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 261986793e..7f6da4fcc2 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 threadId;
+ const std::thread::id threadId;
uv_loop_t *const loop;
CacheRequestBaton *cache_baton = nullptr;
util::ptr<HTTPRequestBaton> httpBaton;
diff --git a/include/mbgl/storage/http_request_baton.hpp b/include/mbgl/storage/http_request_baton.hpp
index c7c80466ba..11abfb71d4 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 threadId;
+ const std::thread::id threadId;
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 73391062e5..f59037c1d8 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 055993db3e..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,49 +85,6 @@ private:
std::function<void ()> fn;
};
-class mutex : public mbgl::util::noncopyable {
- friend class cond;
-
-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 cond : public mbgl::util::noncopyable {
-public:
- inline cond() {
- if (uv_cond_init(&cnd) != 0) {
- throw std::runtime_error("failed to initialize condition variable");
- }
- }
- inline ~cond() { uv_cond_destroy(&cnd); }
- inline void signal() { uv_cond_signal(&cnd); }
- inline void broadcast() { uv_cond_broadcast(&cnd); }
- inline void wait(mutex &mtx) { uv_cond_wait(&cnd, &mtx.mtx); }
- inline void timedwait(mutex &mtx, uint64_t timeout) { uv_cond_timedwait(&cnd, &mtx.mtx, timeout); }
-
-private:
- uv_cond_t cnd;
-};
-
-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() {
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));
}
diff --git a/src/map/map.cpp b/src/map/map.cpp
index 9236c5d2ec..4880bfdce4 100644
--- a/src/map/map.cpp
+++ b/src/map/map.cpp
@@ -94,7 +94,7 @@ Map::Map(View& view_, FileSource& fileSource_)
: loop(util::make_unique<uv::loop>()),
view(view_),
#ifndef NDEBUG
- mainThread(uv_thread_self()),
+ mainThread(std::this_thread::get_id()),
#endif
transform(view_),
fileSource(fileSource_),
@@ -133,8 +133,13 @@ uv::worker &Map::getWorker() {
return *workers;
}
+<<<<<<< HEAD
void Map::start(bool startPaused) {
assert(uv_thread_self() == mainThread);
+=======
+void Map::start() {
+ assert(std::this_thread::get_id() == mainThread);
+>>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b
assert(!async);
// When starting map rendering in another thread, we perform async/continuously
@@ -146,7 +151,7 @@ void Map::start(bool startPaused) {
// Setup async notifications
asyncTerminate = util::make_unique<uv::async>(**loop, [this]() {
- assert(uv_thread_self() == mapThread);
+ assert(std::this_thread::get_id() == mapThread);
// Remove all of these to make sure they are destructed in the correct thread.
glyphStore.reset();
@@ -163,7 +168,7 @@ void Map::start(bool startPaused) {
});
asyncRender = util::make_unique<uv::async>(**loop, [this]() {
- assert(uv_thread_self() == mapThread);
+ assert(std::this_thread::get_id() == mapThread);
if (state.hasSize()) {
if (isRendered.test_and_set() == false) {
@@ -190,9 +195,9 @@ void Map::start(bool startPaused) {
pause();
}
- thread = util::make_unique<uv::thread>([this]() {
+ thread = std::thread([this]() {
#ifndef NDEBUG
- mapThread = uv_thread_self();
+ mapThread = std::this_thread::get_id();
#endif
#ifdef __APPLE__
@@ -202,7 +207,7 @@ void Map::start(bool startPaused) {
run();
#ifndef NDEBUG
- mapThread = -1;
+ mapThread = std::thread::id();
#endif
// Make sure that the stop() function knows when to stop invoking the callback function.
@@ -212,7 +217,7 @@ void Map::start(bool startPaused) {
}
void Map::stop(stop_callback cb, void *data) {
- assert(uv_thread_self() == mainThread);
+ assert(std::this_thread::get_id() == mainThread);
assert(mainThread != mapThread);
assert(async);
@@ -234,7 +239,7 @@ void Map::stop(stop_callback cb, void *data) {
// If a callback function was provided, this should return immediately because the thread has
// already finished executing.
- thread->join();
+ thread.join();
async = false;
}
@@ -277,7 +282,7 @@ void Map::run() {
mapThread = mainThread;
}
#endif
- assert(uv_thread_self() == mapThread);
+ assert(std::this_thread::get_id() == mapThread);
if (async) {
checkForPause();
@@ -304,7 +309,7 @@ void Map::run() {
if (!async) {
render();
#ifndef NDEBUG
- mapThread = -1;
+ mapThread = std::thread::id();
#endif
}
#ifdef __ANDROID__
@@ -379,7 +384,7 @@ void Map::setReachability(bool reachable) {
#pragma mark - Setup
void Map::setup() {
- assert(uv_thread_self() == mapThread);
+ assert(std::this_thread::get_id() == mapThread);
view.make_active();
painter.setup();
}
@@ -653,7 +658,7 @@ uint64_t Map::getDefaultTransitionDuration() {
}
void Map::updateSources() {
- assert(uv_thread_self() == mapThread);
+ assert(std::this_thread::get_id() == mapThread);
// First, disable all existing sources.
for (const auto& source : activeSources) {
diff --git a/src/storage/base_request.cpp b/src/storage/base_request.cpp
index 9ecf0e7ed7..510bd7bf1c 100644
--- a/src/storage/base_request.cpp
+++ b/src/storage/base_request.cpp
@@ -19,13 +19,13 @@ void invoke(const std::forward_list<std::unique_ptr<Callback>> &list, Args&& ...
}
}
-BaseRequest::BaseRequest(const std::string &path_) : threadId(uv_thread_self()), path(path_) {
+BaseRequest::BaseRequest(const std::string &path_) : threadId(std::this_thread::get_id()), path(path_) {
}
// A base request can only be "canceled" by destroying the object. In that case, we'll have to
// notify all cancel callbacks.
BaseRequest::~BaseRequest() {
- assert(uv_thread_self() == threadId);
+ assert(std::this_thread::get_id() == threadId);
notify();
}
@@ -34,7 +34,7 @@ void BaseRequest::retryImmediately() {
}
void BaseRequest::notify() {
- assert(uv_thread_self() == threadId);
+ assert(std::this_thread::get_id() == threadId);
// The parameter exists solely so that any calls to ->remove()
// are not going to cause deallocation of this object while this call is in progress.
@@ -55,7 +55,7 @@ void BaseRequest::notify() {
}
Callback *BaseRequest::add(Callback &&callback, const util::ptr<BaseRequest> &request) {
- assert(uv_thread_self() == threadId);
+ assert(std::this_thread::get_id() == threadId);
assert(this == request.get());
if (response) {
@@ -75,7 +75,7 @@ Callback *BaseRequest::add(Callback &&callback, const util::ptr<BaseRequest> &re
}
void BaseRequest::remove(Callback *callback) {
- assert(uv_thread_self() == threadId);
+ assert(std::this_thread::get_id() == threadId);
callbacks.remove_if([=](const std::unique_ptr<Callback> &cb) {
return cb.get() == callback;
});
diff --git a/src/storage/file_request.cpp b/src/storage/file_request.cpp
index 9534c1a346..6cb882101d 100644
--- a/src/storage/file_request.cpp
+++ b/src/storage/file_request.cpp
@@ -15,7 +15,7 @@ FileRequest::FileRequest(const std::string &path_, uv_loop_t *loop)
}
void FileRequest::cancel() {
- assert(uv_thread_self() == threadId);
+ assert(std::this_thread::get_id() == threadId);
if (ptr) {
ptr->cancel();
@@ -30,7 +30,7 @@ void FileRequest::cancel() {
}
FileRequest::~FileRequest() {
- assert(uv_thread_self() == threadId);
+ assert(std::this_thread::get_id() == threadId);
cancel();
}
diff --git a/src/storage/file_request_baton.cpp b/src/storage/file_request_baton.cpp
index 1e0bcc750d..632e0f3fd2 100644
--- a/src/storage/file_request_baton.cpp
+++ b/src/storage/file_request_baton.cpp
@@ -8,7 +8,7 @@
namespace mbgl {
FileRequestBaton::FileRequestBaton(FileRequest *request_, const std::string &path, uv_loop_t *loop)
- : threadId(uv_thread_self()), request(request_) {
+ : threadId(std::this_thread::get_id()), request(request_) {
req.data = this;
uv_fs_open(loop, &req, path.c_str(), O_RDONLY, S_IRUSR, file_opened);
}
@@ -27,7 +27,7 @@ void FileRequestBaton::cancel() {
void FileRequestBaton::notify_error(uv_fs_t *req) {
FileRequestBaton *ptr = reinterpret_cast<FileRequestBaton *>(req->data);
- assert(ptr->threadId == uv_thread_self());
+ assert(std::this_thread::get_id() == ptr->threadId);
if (ptr->request && req->result < 0 && !ptr->canceled && req->result != UV_ECANCELED) {
ptr->request->response = util::make_unique<Response>();
@@ -43,7 +43,7 @@ void FileRequestBaton::notify_error(uv_fs_t *req) {
void FileRequestBaton::file_opened(uv_fs_t *req) {
FileRequestBaton *ptr = reinterpret_cast<FileRequestBaton *>(req->data);
- assert(ptr->threadId == uv_thread_self());
+ assert(std::this_thread::get_id() == ptr->threadId);
if (req->result < 0) {
// Opening failed or was canceled. There isn't much left we can do.
@@ -68,7 +68,7 @@ void FileRequestBaton::file_opened(uv_fs_t *req) {
void FileRequestBaton::file_stated(uv_fs_t *req) {
FileRequestBaton *ptr = reinterpret_cast<FileRequestBaton *>(req->data);
- assert(ptr->threadId == uv_thread_self());
+ assert(std::this_thread::get_id() == ptr->threadId);
if (req->result != 0 || ptr->canceled || !ptr->request) {
// Stating failed or was canceled. We already have an open file handle
@@ -115,7 +115,7 @@ void FileRequestBaton::file_stated(uv_fs_t *req) {
void FileRequestBaton::file_read(uv_fs_t *req) {
FileRequestBaton *ptr = reinterpret_cast<FileRequestBaton *>(req->data);
- assert(ptr->threadId == uv_thread_self());
+ assert(std::this_thread::get_id() == ptr->threadId);
if (req->result < 0 || ptr->canceled || !ptr->request) {
// Reading failed or was canceled. We already have an open file handle
@@ -136,7 +136,7 @@ void FileRequestBaton::file_read(uv_fs_t *req) {
}
void FileRequestBaton::file_closed(uv_fs_t *req) {
- assert(reinterpret_cast<FileRequestBaton *>(req->data)->threadId == uv_thread_self());
+ assert(std::this_thread::get_id() == reinterpret_cast<FileRequestBaton *>(req->data)->thread_id);
if (req->result < 0) {
// Closing the file failed. But there isn't anything we can do.
@@ -147,7 +147,7 @@ void FileRequestBaton::file_closed(uv_fs_t *req) {
void FileRequestBaton::cleanup(uv_fs_t *req) {
FileRequestBaton *ptr = reinterpret_cast<FileRequestBaton *>(req->data);
- assert(ptr->threadId == uv_thread_self());
+ assert(std::this_thread::get_id() == ptr->threadId);
if (ptr->request) {
ptr->request->ptr = nullptr;
diff --git a/src/storage/http_request.cpp b/src/storage/http_request.cpp
index c127972970..7662484058 100644
--- a/src/storage/http_request.cpp
+++ b/src/storage/http_request.cpp
@@ -22,9 +22,13 @@ struct CacheRequestBaton {
};
HTTPRequest::HTTPRequest(ResourceType type_, const std::string &path_, uv_loop_t *loop_, util::ptr<SQLiteStore> store_)
+<<<<<<< HEAD
: BaseRequest(path_), threadId(uv_thread_self()), loop(loop_), store(store_), type(type_) {
Log::Debug(Event::HttpRequest, "HTTPRequest %s", path.c_str());
+=======
+ : BaseRequest(path_), thread_id(std::this_thread::get_id()), loop(loop_), store(store_), type(type_) {
+>>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b
if (store) {
startCacheRequest();
} else {
@@ -33,7 +37,11 @@ HTTPRequest::HTTPRequest(ResourceType type_, const std::string &path_, uv_loop_t
}
void HTTPRequest::startCacheRequest() {
+<<<<<<< HEAD
assert(uv_thread_self() == threadId);
+=======
+ assert(std::this_thread::get_id() == thread_id);
+>>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b
cache_baton = new CacheRequestBaton;
cache_baton->request = this;
@@ -50,7 +58,11 @@ void HTTPRequest::startCacheRequest() {
}
void HTTPRequest::handleCacheResponse(std::unique_ptr<Response> &&res) {
+<<<<<<< HEAD
assert(uv_thread_self() == threadId);
+=======
+ assert(std::this_thread::get_id() == thread_id);
+>>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b
if (res) {
// This entry was stored in the cache. Now determine if we need to revalidate.
@@ -71,8 +83,13 @@ void HTTPRequest::handleCacheResponse(std::unique_ptr<Response> &&res) {
}
void HTTPRequest::startHTTPRequest(std::unique_ptr<Response> &&res) {
+<<<<<<< HEAD
assert(uv_thread_self() == threadId);
assert(!httpBaton);
+=======
+ assert(std::this_thread::get_id() == thread_id);
+ assert(!http_baton);
+>>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b
httpBaton = std::make_shared<HTTPRequestBaton>(path);
httpBaton->request = this;
@@ -107,8 +124,13 @@ void HTTPRequest::startHTTPRequest(std::unique_ptr<Response> &&res) {
void HTTPRequest::handleHTTPResponse(HTTPResponseType responseType, std::unique_ptr<Response> &&res) {
+<<<<<<< HEAD
assert(uv_thread_self() == threadId);
assert(!httpBaton);
+=======
+ assert(std::this_thread::get_id() == thread_id);
+ assert(!http_baton);
+>>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b
assert(!response);
switch (responseType) {
@@ -195,7 +217,11 @@ void HTTPRequest::handleHTTPResponse(HTTPResponseType responseType, std::unique_
using RetryBaton = std::pair<HTTPRequest *, std::unique_ptr<Response>>;
void HTTPRequest::retryHTTPRequest(std::unique_ptr<Response> &&res, uint64_t timeout) {
+<<<<<<< HEAD
assert(uv_thread_self() == threadId);
+=======
+ assert(std::this_thread::get_id() == thread_id);
+>>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b
assert(!backoff_timer);
backoff_timer = new uv_timer_t();
uv_timer_init(loop, backoff_timer);
@@ -215,16 +241,28 @@ void HTTPRequest::retryHTTPRequest(std::unique_ptr<Response> &&res, uint64_t tim
}
void HTTPRequest::removeHTTPBaton() {
+<<<<<<< HEAD
assert(uv_thread_self() == threadId);
if (httpBaton) {
httpBaton->request = nullptr;
HTTPRequestBaton::stop(httpBaton);
httpBaton.reset();
+=======
+ assert(std::this_thread::get_id() == thread_id);
+ if (http_baton) {
+ http_baton->request = nullptr;
+ HTTPRequestBaton::stop(http_baton);
+ http_baton.reset();
+>>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b
}
}
void HTTPRequest::removeCacheBaton() {
+<<<<<<< HEAD
assert(uv_thread_self() == threadId);
+=======
+ assert(std::this_thread::get_id() == thread_id);
+>>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b
if (cache_baton) {
// Make sre that this object doesn't accidentally get accessed when it is destructed before
// the callback returned. They are being run in the same thread, so just setting it to
@@ -237,7 +275,11 @@ void HTTPRequest::removeCacheBaton() {
}
void HTTPRequest::removeBackoffTimer() {
+<<<<<<< HEAD
assert(uv_thread_self() == threadId);
+=======
+ assert(std::this_thread::get_id() == thread_id);
+>>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b
if (backoff_timer) {
delete static_cast<RetryBaton *>(backoff_timer->data);
uv_timer_stop(backoff_timer);
@@ -247,8 +289,13 @@ void HTTPRequest::removeBackoffTimer() {
}
void HTTPRequest::retryImmediately() {
+<<<<<<< HEAD
assert(uv_thread_self() == threadId);
if (!cache_baton && !httpBaton) {
+=======
+ assert(std::this_thread::get_id() == thread_id);
+ if (!cache_baton && !http_baton) {
+>>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b
if (backoff_timer) {
// Retry immediately.
uv_timer_stop(backoff_timer);
@@ -264,7 +311,11 @@ void HTTPRequest::retryImmediately() {
}
void HTTPRequest::cancel() {
+<<<<<<< HEAD
assert(uv_thread_self() == threadId);
+=======
+ assert(std::this_thread::get_id() == thread_id);
+>>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b
removeCacheBaton();
removeHTTPBaton();
removeBackoffTimer();
@@ -273,7 +324,11 @@ void HTTPRequest::cancel() {
HTTPRequest::~HTTPRequest() {
+<<<<<<< HEAD
assert(uv_thread_self() == threadId);
+=======
+ assert(std::this_thread::get_id() == thread_id);
+>>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b
cancel();
}
diff --git a/src/storage/http_request_baton.cpp b/src/storage/http_request_baton.cpp
index e1ae422328..7102c20e1f 100644
--- a/src/storage/http_request_baton.cpp
+++ b/src/storage/http_request_baton.cpp
@@ -3,7 +3,11 @@
namespace mbgl {
+<<<<<<< HEAD
HTTPRequestBaton::HTTPRequestBaton(const std::string &path_) : threadId(uv_thread_self()), path(path_) {
+=======
+HTTPRequestBaton::HTTPRequestBaton(const std::string &path_) : thread_id(std::this_thread::get_id()), path(path_) {
+>>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b
}
HTTPRequestBaton::~HTTPRequestBaton() {
diff --git a/src/storage/request.cpp b/src/storage/request.cpp
index 42bf87a849..39fbd36789 100644
--- a/src/storage/request.cpp
+++ b/src/storage/request.cpp
@@ -8,15 +8,15 @@
namespace mbgl {
Request::Request(const util::ptr<BaseRequest> &base_)
- : thread_id(uv_thread_self()), base(base_) {
+ : thread_id(std::this_thread::get_id()), base(base_) {
}
Request::~Request() {
- assert(thread_id == uv_thread_self());
+ assert(thread_id == std::this_thread::get_id());
}
void Request::onload(CompletedCallback cb) {
- assert(thread_id == uv_thread_self());
+ assert(thread_id == std::this_thread::get_id());
if (base) {
Callback *callback = base->add(std::move(cb), base);
if (callback) {
@@ -26,7 +26,7 @@ void Request::onload(CompletedCallback cb) {
}
void Request::oncancel(AbortedCallback cb) {
- assert(thread_id == uv_thread_self());
+ assert(thread_id == std::this_thread::get_id());
if (base) {
Callback *callback = base->add(std::move(cb), base);
if (callback) {
@@ -36,7 +36,7 @@ void Request::oncancel(AbortedCallback cb) {
}
void Request::cancel() {
- assert(thread_id == uv_thread_self());
+ assert(thread_id == std::this_thread::get_id());
if (base) {
for (Callback *callback : callbacks) {
base->remove(callback);
diff --git a/src/storage/sqlite_store.cpp b/src/storage/sqlite_store.cpp
index bc262e386a..d382921dec 100644
--- a/src/storage/sqlite_store.cpp
+++ b/src/storage/sqlite_store.cpp
@@ -58,7 +58,7 @@ std::string unifyMapboxURLs(const std::string &url) {
namespace mbgl {
SQLiteStore::SQLiteStore(uv_loop_t *loop, const std::string &path)
- : thread_id(uv_thread_self()),
+ : thread_id(std::this_thread::get_id()),
db(std::make_shared<Database>(path.c_str(), ReadWrite | Create)) {
createSchema();
worker = new uv_worker_t;
@@ -103,7 +103,7 @@ struct GetBaton {
};
void SQLiteStore::get(const std::string &path, GetCallback callback, void *ptr) {
- assert(uv_thread_self() == thread_id);
+ assert(std::this_thread::get_id() == thread_id);
if (!db || !*db) {
if (callback) {
callback(nullptr, ptr);
@@ -160,7 +160,7 @@ struct PutBaton {
};
void SQLiteStore::put(const std::string &path, ResourceType type, const Response &response) {
- assert(uv_thread_self() == thread_id);
+ assert(std::this_thread::get_id() == thread_id);
if (!db) return;
PutBaton *put_baton = new PutBaton;
@@ -204,7 +204,7 @@ struct ExpirationBaton {
};
void SQLiteStore::updateExpiration(const std::string &path, int64_t expires) {
- assert(uv_thread_self() == thread_id);
+ assert(std::this_thread::get_id() == thread_id);
if (!db || !*db) return;
ExpirationBaton *expiration_baton = new ExpirationBaton;