diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 718efbf14..4e6eef89c 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -9,8 +9,10 @@ #include #include #include + #include #include +#include #include #include #include @@ -147,7 +149,7 @@ private: bool async = false; std::unique_ptr loop; std::unique_ptr workers; - std::unique_ptr thread; + std::thread thread; std::unique_ptr asyncTerminate; std::unique_ptr asyncRender; std::unique_ptr 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 fe6972230..c39447488 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 +#include #include 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 16ff24faa..2913c5eae 100644 --- a/include/mbgl/storage/base_request.hpp +++ b/include/mbgl/storage/base_request.hpp @@ -7,7 +7,7 @@ #include #include #include - +#include 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; diff --git a/include/mbgl/storage/file_request_baton.hpp b/include/mbgl/storage/file_request_baton.hpp index 0f1968ca1..897c88061 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 +#include #include @@ -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 ec76f1147..71d6e8814 100644 --- a/include/mbgl/storage/http_request.hpp +++ b/include/mbgl/storage/http_request.hpp @@ -8,6 +8,7 @@ #include #include #include +#include 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 http_baton; diff --git a/include/mbgl/storage/http_request_baton.hpp b/include/mbgl/storage/http_request_baton.hpp index 279784ec2..545f9e236 100644 --- a/include/mbgl/storage/http_request_baton.hpp +++ b/include/mbgl/storage/http_request_baton.hpp @@ -5,6 +5,7 @@ #include #include +#include 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 e603ee527..11b5541d1 100644 --- a/include/mbgl/storage/request.hpp +++ b/include/mbgl/storage/request.hpp @@ -5,6 +5,7 @@ #include #include +#include #include 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 base; std::forward_list callbacks; }; diff --git a/include/mbgl/storage/sqlite_store.hpp b/include/mbgl/storage/sqlite_store.hpp index cb7730d0b..a691b474e 100644 --- a/include/mbgl/storage/sqlite_store.hpp +++ b/include/mbgl/storage/sqlite_store.hpp @@ -7,6 +7,7 @@ #include #include +#include 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 db; uv_worker_t *worker = nullptr; }; diff --git a/include/mbgl/util/uv.hpp b/include/mbgl/util/uv.hpp index 2fc3e0dc3..74ed9c87a 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 b6b9be208..99f5edc14 100644 --- a/include/mbgl/util/uv_detail.hpp +++ b/include/mbgl/util/uv_detail.hpp @@ -20,30 +20,6 @@ void close(std::unique_ptr ptr) { }); } -class thread : public mbgl::util::noncopyable { -public: - inline thread(std::function 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(data)->fn(); - } - - uv_thread_t t; - std::function fn; -}; - class loop : public mbgl::util::noncopyable { public: inline loop() { @@ -109,30 +85,6 @@ private: std::function 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() { diff --git a/platform/darwin/http_request_baton_cocoa.mm b/platform/darwin/http_request_baton_cocoa.mm index 28afbb508..1c256d0ba 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 &ptr) { - assert(uv_thread_self() == ptr->thread_id); + assert(std::this_thread::get_id() == ptr->thread_id); // Starts the request. util::ptr baton = ptr; @@ -131,7 +131,7 @@ void HTTPRequestBaton::start(const util::ptr &ptr) { } void HTTPRequestBaton::stop(const util::ptr &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 4ea85dd2c..3e74f5ed0 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(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 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 CachingHTTPFileSource::request(ResourceType type, const } void CachingHTTPFileSource::prepare(std::function fn) { - if (thread_id == uv_thread_self()) { + if (thread_id == std::this_thread::get_id()) { fn(); } else { uv_messenger_send(queue, new std::function(std::move(fn))); @@ -101,7 +101,7 @@ void CachingHTTPFileSource::prepare(std::function fn) { } void CachingHTTPFileSource::retryAllPending() { - assert(thread_id == uv_thread_self()); + assert(thread_id == std::this_thread::get_id()); util::ptr req; for (const std::pair> &pair : pending) { diff --git a/platform/default/http_request_baton_curl.cpp b/platform/default/http_request_baton_curl.cpp index 4b825622a..f05ee5acf 100644 --- a/platform/default/http_request_baton_curl.cpp +++ b/platform/default/http_request_baton_curl.cpp @@ -10,6 +10,7 @@ #include #include #include +#include // 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 *)ptr; delete (util::ptr *)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 &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(ptr)); } // This function must be run from the main thread (== where the HTTPRequestBaton was created) void HTTPRequestBaton::stop(const util::ptr &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(ptr)); } diff --git a/src/map/map.cpp b/src/map/map.cpp index a33200fe0..822a98d63 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -89,7 +89,7 @@ Map::Map(View& view_, FileSource& fileSource_) : loop(util::make_unique()), view(view_), #ifndef NDEBUG - mainThread(uv_thread_self()), + mainThread(std::this_thread::get_id()), #endif transform(view_), fileSource(fileSource_), @@ -129,7 +129,7 @@ uv::worker &Map::getWorker() { } void Map::start() { - assert(uv_thread_self() == mainThread); + assert(std::this_thread::get_id() == mainThread); assert(!async); // When starting map rendering in another thread, we perform async/continuously @@ -141,7 +141,7 @@ void Map::start() { // Setup async notifications asyncTerminate = util::make_unique(**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(); @@ -156,7 +156,7 @@ void Map::start() { }); asyncRender = util::make_unique(**loop, [this]() { - assert(uv_thread_self() == mapThread); + assert(std::this_thread::get_id() == mapThread); if (state.hasSize()) { if (isRendered.test_and_set() == false) { @@ -178,9 +178,9 @@ void Map::start() { painter.cleanup(); }); - thread = util::make_unique([this]() { + thread = std::thread([this]() { #ifndef NDEBUG - mapThread = uv_thread_self(); + mapThread = std::this_thread::get_id(); #endif #ifdef __APPLE__ @@ -190,7 +190,7 @@ void Map::start() { run(); #ifndef NDEBUG - mapThread = -1; + mapThread = std::thread::id(); #endif // Make sure that the stop() function knows when to stop invoking the callback function. @@ -200,7 +200,7 @@ void Map::start() { } 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); @@ -220,7 +220,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; } @@ -231,7 +231,7 @@ void Map::run() { mapThread = mainThread; } #endif - assert(uv_thread_self() == mapThread); + assert(std::this_thread::get_id() == mapThread); setup(); prepare(); @@ -245,7 +245,7 @@ void Map::run() { if (!async) { render(); #ifndef NDEBUG - mapThread = -1; + mapThread = std::thread::id(); #endif } } @@ -294,7 +294,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(); view.make_inactive(); @@ -536,7 +536,7 @@ void Map::setDefaultTransitionDuration(uint64_t milliseconds) { } 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 9819dc89f..5ce206996 100644 --- a/src/storage/base_request.cpp +++ b/src/storage/base_request.cpp @@ -19,13 +19,13 @@ void invoke(const std::forward_list> &list, Args&& ... } } -BaseRequest::BaseRequest(const std::string &path_) : thread_id(uv_thread_self()), path(path_) { +BaseRequest::BaseRequest(const std::string &path_) : thread_id(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(thread_id == uv_thread_self()); + assert(thread_id == std::this_thread::get_id()); notify(); } @@ -34,7 +34,7 @@ void BaseRequest::retryImmediately() { } void BaseRequest::notify() { - assert(thread_id == uv_thread_self()); + assert(thread_id == std::this_thread::get_id()); // 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 &request) { - assert(thread_id == uv_thread_self()); + assert(thread_id == std::this_thread::get_id()); assert(this == request.get()); if (response) { @@ -75,7 +75,7 @@ Callback *BaseRequest::add(Callback &&callback, const util::ptr &re } void BaseRequest::remove(Callback *callback) { - assert(thread_id == uv_thread_self()); + assert(thread_id == std::this_thread::get_id()); callbacks.remove_if([=](const std::unique_ptr &cb) { return cb.get() == callback; }); diff --git a/src/storage/file_request.cpp b/src/storage/file_request.cpp index 33398d5ef..9f74c7b41 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(thread_id == uv_thread_self()); + assert(thread_id == std::this_thread::get_id()); if (ptr) { ptr->cancel(); @@ -30,7 +30,7 @@ void FileRequest::cancel() { } FileRequest::~FileRequest() { - assert(thread_id == uv_thread_self()); + assert(thread_id == std::this_thread::get_id()); cancel(); } diff --git a/src/storage/file_request_baton.cpp b/src/storage/file_request_baton.cpp index 75ea95df4..0a9c5f6f5 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) - : thread_id(uv_thread_self()), request(request_) { + : thread_id(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 = (FileRequestBaton *)req->data; - assert(ptr->thread_id == uv_thread_self()); + assert(ptr->thread_id == std::this_thread::get_id()); if (ptr->request && req->result < 0 && !ptr->canceled && req->result != UV_ECANCELED) { ptr->request->response = util::make_unique(); @@ -43,7 +43,7 @@ void FileRequestBaton::notify_error(uv_fs_t *req) { void FileRequestBaton::file_opened(uv_fs_t *req) { FileRequestBaton *ptr = (FileRequestBaton *)req->data; - assert(ptr->thread_id == uv_thread_self()); + assert(ptr->thread_id == std::this_thread::get_id()); 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 = (FileRequestBaton *)req->data; - assert(ptr->thread_id == uv_thread_self()); + assert(ptr->thread_id == std::this_thread::get_id()); 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 = (FileRequestBaton *)req->data; - assert(ptr->thread_id == uv_thread_self()); + assert(ptr->thread_id == std::this_thread::get_id()); if (req->result < 0 || ptr->canceled || !ptr->request) { // Stating 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(((FileRequestBaton *)req->data)->thread_id == uv_thread_self()); + assert(((FileRequestBaton *)req->data)->thread_id == std::this_thread::get_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 = (FileRequestBaton *)req->data; - assert(ptr->thread_id == uv_thread_self()); + assert(ptr->thread_id == std::this_thread::get_id()); if (ptr->request) { ptr->request->ptr = nullptr; diff --git a/src/storage/http_request.cpp b/src/storage/http_request.cpp index c87a92e12..ebb9a8482 100644 --- a/src/storage/http_request.cpp +++ b/src/storage/http_request.cpp @@ -21,7 +21,7 @@ struct CacheRequestBaton { }; HTTPRequest::HTTPRequest(ResourceType type_, const std::string &path_, uv_loop_t *loop_, util::ptr store_) - : BaseRequest(path_), thread_id(uv_thread_self()), loop(loop_), store(store_), type(type_) { + : BaseRequest(path_), thread_id(std::this_thread::get_id()), loop(loop_), store(store_), type(type_) { if (store) { startCacheRequest(); } else { @@ -30,7 +30,7 @@ HTTPRequest::HTTPRequest(ResourceType type_, const std::string &path_, uv_loop_t } void HTTPRequest::startCacheRequest() { - assert(uv_thread_self() == thread_id); + assert(std::this_thread::get_id() == thread_id); cache_baton = new CacheRequestBaton; cache_baton->request = this; @@ -47,7 +47,7 @@ void HTTPRequest::startCacheRequest() { } void HTTPRequest::handleCacheResponse(std::unique_ptr &&res) { - assert(uv_thread_self() == thread_id); + assert(std::this_thread::get_id() == thread_id); if (res) { // This entry was stored in the cache. Now determine if we need to revalidate. @@ -68,7 +68,7 @@ void HTTPRequest::handleCacheResponse(std::unique_ptr &&res) { } void HTTPRequest::startHTTPRequest(std::unique_ptr &&res) { - assert(uv_thread_self() == thread_id); + assert(std::this_thread::get_id() == thread_id); assert(!http_baton); http_baton = std::make_shared(path); @@ -104,7 +104,7 @@ void HTTPRequest::startHTTPRequest(std::unique_ptr &&res) { void HTTPRequest::handleHTTPResponse(HTTPResponseType responseType, std::unique_ptr &&res) { - assert(uv_thread_self() == thread_id); + assert(std::this_thread::get_id() == thread_id); assert(!http_baton); assert(!response); @@ -192,7 +192,7 @@ void HTTPRequest::handleHTTPResponse(HTTPResponseType responseType, std::unique_ using RetryBaton = std::pair>; void HTTPRequest::retryHTTPRequest(std::unique_ptr &&res, uint64_t timeout) { - assert(uv_thread_self() == thread_id); + assert(std::this_thread::get_id() == thread_id); assert(!backoff_timer); backoff_timer = new uv_timer_t(); uv_timer_init(loop, backoff_timer); @@ -212,7 +212,7 @@ void HTTPRequest::retryHTTPRequest(std::unique_ptr &&res, uint64_t tim } void HTTPRequest::removeHTTPBaton() { - assert(uv_thread_self() == thread_id); + assert(std::this_thread::get_id() == thread_id); if (http_baton) { http_baton->request = nullptr; HTTPRequestBaton::stop(http_baton); @@ -221,7 +221,7 @@ void HTTPRequest::removeHTTPBaton() { } void HTTPRequest::removeCacheBaton() { - assert(uv_thread_self() == thread_id); + assert(std::this_thread::get_id() == thread_id); 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 @@ -234,7 +234,7 @@ void HTTPRequest::removeCacheBaton() { } void HTTPRequest::removeBackoffTimer() { - assert(uv_thread_self() == thread_id); + assert(std::this_thread::get_id() == thread_id); if (backoff_timer) { delete static_cast(backoff_timer->data); uv_timer_stop(backoff_timer); @@ -244,7 +244,7 @@ void HTTPRequest::removeBackoffTimer() { } void HTTPRequest::retryImmediately() { - assert(uv_thread_self() == thread_id); + assert(std::this_thread::get_id() == thread_id); if (!cache_baton && !http_baton) { if (backoff_timer) { // Retry immediately. @@ -261,7 +261,7 @@ void HTTPRequest::retryImmediately() { } void HTTPRequest::cancel() { - assert(uv_thread_self() == thread_id); + assert(std::this_thread::get_id() == thread_id); removeCacheBaton(); removeHTTPBaton(); removeBackoffTimer(); @@ -270,7 +270,7 @@ void HTTPRequest::cancel() { HTTPRequest::~HTTPRequest() { - assert(uv_thread_self() == thread_id); + assert(std::this_thread::get_id() == thread_id); cancel(); } diff --git a/src/storage/http_request_baton.cpp b/src/storage/http_request_baton.cpp index 02edae748..315708f4e 100644 --- a/src/storage/http_request_baton.cpp +++ b/src/storage/http_request_baton.cpp @@ -3,7 +3,7 @@ namespace mbgl { -HTTPRequestBaton::HTTPRequestBaton(const std::string &path_) : thread_id(uv_thread_self()), path(path_) { +HTTPRequestBaton::HTTPRequestBaton(const std::string &path_) : thread_id(std::this_thread::get_id()), path(path_) { } HTTPRequestBaton::~HTTPRequestBaton() { diff --git a/src/storage/request.cpp b/src/storage/request.cpp index 42bf87a84..39fbd3678 100644 --- a/src/storage/request.cpp +++ b/src/storage/request.cpp @@ -8,15 +8,15 @@ namespace mbgl { Request::Request(const util::ptr &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 bc262e386..d382921de 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(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;