diff --git a/include/mbgl/storage/base_request.hpp b/include/mbgl/storage/base_request.hpp index 16ff24faa..82372416d 100644 --- a/include/mbgl/storage/base_request.hpp +++ b/include/mbgl/storage/base_request.hpp @@ -46,7 +46,7 @@ public: virtual void retryImmediately(); public: - const unsigned long thread_id; + const unsigned long threadId; const std::string path; std::unique_ptr response; diff --git a/include/mbgl/storage/http_request.hpp b/include/mbgl/storage/http_request.hpp index ec76f1147..261986793 100644 --- a/include/mbgl/storage/http_request.hpp +++ b/include/mbgl/storage/http_request.hpp @@ -40,10 +40,10 @@ private: void removeBackoffTimer(); private: - const unsigned long thread_id; + const unsigned long threadId; uv_loop_t *const loop; CacheRequestBaton *cache_baton = nullptr; - util::ptr http_baton; + util::ptr httpBaton; uv_timer_t *backoff_timer = nullptr; util::ptr store; const ResourceType type; @@ -54,4 +54,4 @@ private: } -#endif \ No newline at end of file +#endif diff --git a/platform/android/asset_request_baton_libzip.cpp b/platform/android/asset_request_baton_libzip.cpp index 6508f469d..628e9c93b 100644 --- a/platform/android/asset_request_baton_libzip.cpp +++ b/platform/android/asset_request_baton_libzip.cpp @@ -9,11 +9,12 @@ // See https://code.google.com/p/android/issues/detail?id=72349 // After this is fixed change usage errno to std::errno #include +#include namespace mbgl { void AssetRequestBaton::run(AssetRequestBaton *ptr) { - assert(ptr->threadId == uv_thread_self()); + assert(uv_thread_self() == ptr->threadId); if (ptr->canceled || !ptr->request) { // Either the AssetRequest object has been destructed, or the diff --git a/platform/default/asset_request_baton_noop.cpp b/platform/default/asset_request_baton_noop.cpp index 45083a50f..2f3202650 100644 --- a/platform/default/asset_request_baton_noop.cpp +++ b/platform/default/asset_request_baton_noop.cpp @@ -2,10 +2,12 @@ #include #include +#include + namespace mbgl { void AssetRequestBaton::run(AssetRequestBaton *ptr) { - assert(ptr->threadId == uv_thread_self()); + assert(uv_thread_self() == ptr->threadId); if (ptr->canceled || !ptr->request) { // Either the AssetRequest object has been destructed, or the diff --git a/src/storage/asset_request.cpp b/src/storage/asset_request.cpp index 0d0eed2c7..7063f7131 100644 --- a/src/storage/asset_request.cpp +++ b/src/storage/asset_request.cpp @@ -15,7 +15,7 @@ AssetRequest::AssetRequest(const std::string &path_, uv_loop_t *loop) } void AssetRequest::cancel() { - assert(thread_id == uv_thread_self()); + assert(uv_thread_self() == threadId); if (ptr) { ptr->cancel(); @@ -30,7 +30,7 @@ void AssetRequest::cancel() { } AssetRequest::~AssetRequest() { - assert(thread_id == uv_thread_self()); + assert(uv_thread_self() == threadId); cancel(); } diff --git a/src/storage/asset_request_baton.cpp b/src/storage/asset_request_baton.cpp index a0e4149b9..952eb7c6a 100644 --- a/src/storage/asset_request_baton.cpp +++ b/src/storage/asset_request_baton.cpp @@ -25,7 +25,7 @@ void AssetRequestBaton::cancel() { } void AssetRequestBaton::notify_error(AssetRequestBaton *ptr, const int code, const char *message) { - assert(ptr->threadId == uv_thread_self()); + assert(uv_thread_self() == ptr->threadId); if (ptr->request && !ptr->canceled) { ptr->request->response = std::unique_ptr(new Response); @@ -36,7 +36,7 @@ void AssetRequestBaton::notify_error(AssetRequestBaton *ptr, const int code, con } void AssetRequestBaton::cleanup(AssetRequestBaton *ptr) { - assert(ptr->threadId == uv_thread_self()); + assert(uv_thread_self() == ptr->threadId); if (ptr->request) { ptr->request->ptr = nullptr; diff --git a/src/storage/base_request.cpp b/src/storage/base_request.cpp index 9819dc89f..9ecf0e7ed 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_) : threadId(uv_thread_self()), 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(uv_thread_self() == threadId); notify(); } @@ -34,7 +34,7 @@ void BaseRequest::retryImmediately() { } void BaseRequest::notify() { - assert(thread_id == uv_thread_self()); + assert(uv_thread_self() == 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 &request) { - assert(thread_id == uv_thread_self()); + assert(uv_thread_self() == threadId); 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(uv_thread_self() == threadId); 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..9534c1a34 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(uv_thread_self() == threadId); if (ptr) { ptr->cancel(); @@ -30,7 +30,7 @@ void FileRequest::cancel() { } FileRequest::~FileRequest() { - assert(thread_id == uv_thread_self()); + assert(uv_thread_self() == threadId); cancel(); } diff --git a/src/storage/file_request_baton.cpp b/src/storage/file_request_baton.cpp index bfb047a47..1e0bcc750 100644 --- a/src/storage/file_request_baton.cpp +++ b/src/storage/file_request_baton.cpp @@ -27,7 +27,7 @@ void FileRequestBaton::cancel() { void FileRequestBaton::notify_error(uv_fs_t *req) { FileRequestBaton *ptr = reinterpret_cast(req->data); - assert(ptr->thread_id == uv_thread_self()); + assert(ptr->threadId == uv_thread_self()); 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 = reinterpret_cast(req->data); - assert(ptr->thread_id == uv_thread_self()); + assert(ptr->threadId == uv_thread_self()); 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(req->data); - assert(ptr->thread_id == uv_thread_self()); + assert(ptr->threadId == uv_thread_self()); 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(req->data); - assert(ptr->thread_id == uv_thread_self()); + assert(ptr->threadId == uv_thread_self()); 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(req->data)->thread_id == uv_thread_self()); + assert(reinterpret_cast(req->data)->threadId == uv_thread_self()); 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(req->data); - assert(ptr->thread_id == uv_thread_self()); + assert(ptr->threadId == uv_thread_self()); if (ptr->request) { ptr->request->ptr = nullptr; diff --git a/src/storage/http_request.cpp b/src/storage/http_request.cpp index f19436e23..c12797297 100644 --- a/src/storage/http_request.cpp +++ b/src/storage/http_request.cpp @@ -22,7 +22,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_), threadId(uv_thread_self()), loop(loop_), store(store_), type(type_) { Log::Debug(Event::HttpRequest, "HTTPRequest %s", path.c_str()); if (store) { @@ -33,7 +33,7 @@ HTTPRequest::HTTPRequest(ResourceType type_, const std::string &path_, uv_loop_t } void HTTPRequest::startCacheRequest() { - assert(uv_thread_self() == thread_id); + assert(uv_thread_self() == threadId); cache_baton = new CacheRequestBaton; cache_baton->request = this; @@ -50,7 +50,7 @@ void HTTPRequest::startCacheRequest() { } void HTTPRequest::handleCacheResponse(std::unique_ptr &&res) { - assert(uv_thread_self() == thread_id); + assert(uv_thread_self() == threadId); if (res) { // This entry was stored in the cache. Now determine if we need to revalidate. @@ -71,25 +71,25 @@ void HTTPRequest::handleCacheResponse(std::unique_ptr &&res) { } void HTTPRequest::startHTTPRequest(std::unique_ptr &&res) { - assert(uv_thread_self() == thread_id); - assert(!http_baton); + assert(uv_thread_self() == threadId); + assert(!httpBaton); - http_baton = std::make_shared(path); - http_baton->request = this; - http_baton->async = new uv_async_t; - http_baton->response = std::move(res); - http_baton->async->data = new util::ptr(http_baton); + httpBaton = std::make_shared(path); + httpBaton->request = this; + httpBaton->async = new uv_async_t; + httpBaton->response = std::move(res); + httpBaton->async->data = new util::ptr(httpBaton); #if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 - uv_async_init(loop, http_baton->async, [](uv_async_t *async, int) { + uv_async_init(loop, httpBaton->async, [](uv_async_t *async, int) { #else - uv_async_init(loop, http_baton->async, [](uv_async_t *async) { + uv_async_init(loop, httpBaton->async, [](uv_async_t *async) { #endif util::ptr &baton = *(util::ptr *)async->data; if (baton->request) { HTTPRequest *request = baton->request; - request->http_baton.reset(); + request->httpBaton.reset(); baton->request = nullptr; request->handleHTTPResponse(baton->type, std::move(baton->response)); } @@ -101,14 +101,14 @@ void HTTPRequest::startHTTPRequest(std::unique_ptr &&res) { }); }); attempts++; - HTTPRequestBaton::start(http_baton); + HTTPRequestBaton::start(httpBaton); } void HTTPRequest::handleHTTPResponse(HTTPResponseType responseType, std::unique_ptr &&res) { - assert(uv_thread_self() == thread_id); - assert(!http_baton); + assert(uv_thread_self() == threadId); + assert(!httpBaton); assert(!response); switch (responseType) { @@ -195,7 +195,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(uv_thread_self() == threadId); assert(!backoff_timer); backoff_timer = new uv_timer_t(); uv_timer_init(loop, backoff_timer); @@ -215,16 +215,16 @@ void HTTPRequest::retryHTTPRequest(std::unique_ptr &&res, uint64_t tim } void HTTPRequest::removeHTTPBaton() { - assert(uv_thread_self() == thread_id); - if (http_baton) { - http_baton->request = nullptr; - HTTPRequestBaton::stop(http_baton); - http_baton.reset(); + assert(uv_thread_self() == threadId); + if (httpBaton) { + httpBaton->request = nullptr; + HTTPRequestBaton::stop(httpBaton); + httpBaton.reset(); } } void HTTPRequest::removeCacheBaton() { - assert(uv_thread_self() == thread_id); + assert(uv_thread_self() == threadId); 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 +237,7 @@ void HTTPRequest::removeCacheBaton() { } void HTTPRequest::removeBackoffTimer() { - assert(uv_thread_self() == thread_id); + assert(uv_thread_self() == threadId); if (backoff_timer) { delete static_cast(backoff_timer->data); uv_timer_stop(backoff_timer); @@ -247,8 +247,8 @@ void HTTPRequest::removeBackoffTimer() { } void HTTPRequest::retryImmediately() { - assert(uv_thread_self() == thread_id); - if (!cache_baton && !http_baton) { + assert(uv_thread_self() == threadId); + if (!cache_baton && !httpBaton) { if (backoff_timer) { // Retry immediately. uv_timer_stop(backoff_timer); @@ -264,7 +264,7 @@ void HTTPRequest::retryImmediately() { } void HTTPRequest::cancel() { - assert(uv_thread_self() == thread_id); + assert(uv_thread_self() == threadId); removeCacheBaton(); removeHTTPBaton(); removeBackoffTimer(); @@ -273,7 +273,7 @@ void HTTPRequest::cancel() { HTTPRequest::~HTTPRequest() { - assert(uv_thread_self() == thread_id); + assert(uv_thread_self() == threadId); cancel(); }