From 1c0396690e9eba8e588f5553790ba8407dd55f34 Mon Sep 17 00:00:00 2001 From: Leith Bade Date: Thu, 4 Dec 2014 22:39:38 +1100 Subject: [PATCH] Fixup after merge --- .../default/caching_http_file_source.hpp | 2 +- include/mbgl/storage/asset_request_baton.hpp | 5 +- include/mbgl/storage/http_request.hpp | 4 +- .../android/asset_request_baton_libzip.cpp | 3 +- platform/default/asset_request_baton_noop.cpp | 4 +- platform/default/caching_http_file_source.cpp | 12 +- src/map/map.cpp | 5 - src/storage/asset_request.cpp | 4 +- src/storage/asset_request_baton.cpp | 8 +- src/storage/http_request.cpp | 137 +++++------------- src/storage/http_request_baton.cpp | 6 +- 11 files changed, 61 insertions(+), 129 deletions(-) diff --git a/include/mbgl/platform/default/caching_http_file_source.hpp b/include/mbgl/platform/default/caching_http_file_source.hpp index c39447488..1db95c699 100644 --- a/include/mbgl/platform/default/caching_http_file_source.hpp +++ b/include/mbgl/platform/default/caching_http_file_source.hpp @@ -33,7 +33,7 @@ public: void retryAllPending(); private: - std::thread::id thread_id; + std::thread::id threadId; // Path to the cache database. std::string path; diff --git a/include/mbgl/storage/asset_request_baton.hpp b/include/mbgl/storage/asset_request_baton.hpp index 7f7bd69c6..8506dc9b6 100644 --- a/include/mbgl/storage/asset_request_baton.hpp +++ b/include/mbgl/storage/asset_request_baton.hpp @@ -3,13 +3,16 @@ #include #include +#include + +#include namespace mbgl { struct AssetRequestBaton { AssetRequestBaton(AssetRequest *request_, const std::string &path, uv_loop_t *loop); - const unsigned long threadId; + const std::thread::id threadId; AssetRequest *request = nullptr; std::unique_ptr asyncRun; std::string path; diff --git a/include/mbgl/storage/http_request.hpp b/include/mbgl/storage/http_request.hpp index 7f6da4fcc..7cc72101d 100644 --- a/include/mbgl/storage/http_request.hpp +++ b/include/mbgl/storage/http_request.hpp @@ -43,9 +43,9 @@ private: private: const std::thread::id threadId; uv_loop_t *const loop; - CacheRequestBaton *cache_baton = nullptr; + CacheRequestBaton *cacheBaton = nullptr; util::ptr httpBaton; - uv_timer_t *backoff_timer = nullptr; + uv_timer_t *backoffTimer = nullptr; util::ptr store; const ResourceType type; uint8_t attempts = 0; diff --git a/platform/android/asset_request_baton_libzip.cpp b/platform/android/asset_request_baton_libzip.cpp index 7fc86ae1b..205c42bf4 100644 --- a/platform/android/asset_request_baton_libzip.cpp +++ b/platform/android/asset_request_baton_libzip.cpp @@ -9,12 +9,11 @@ // 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(uv_thread_self() == ptr->threadId); + assert(std::this_thread::get_id() == 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 2f3202650..88550367b 100644 --- a/platform/default/asset_request_baton_noop.cpp +++ b/platform/default/asset_request_baton_noop.cpp @@ -2,12 +2,10 @@ #include #include -#include - namespace mbgl { void AssetRequestBaton::run(AssetRequestBaton *ptr) { - assert(uv_thread_self() == ptr->threadId); + assert(std::this_thread::get_id() == ptr->threadId); if (ptr->canceled || !ptr->request) { // Either the AssetRequest object has been destructed, or the diff --git a/platform/default/caching_http_file_source.cpp b/platform/default/caching_http_file_source.cpp index 20525a264..f1dc55fb0 100644 --- a/platform/default/caching_http_file_source.cpp +++ b/platform/default/caching_http_file_source.cpp @@ -33,7 +33,7 @@ CachingHTTPFileSource::~CachingHTTPFileSource() { } void CachingHTTPFileSource::setLoop(uv_loop_t* loop_) { - thread_id = std::this_thread::get_id(); + threadId = std::this_thread::get_id(); store = !path.empty() ? util::ptr(new SQLiteStore(loop_, path)) : nullptr; loop = loop_; queue = new uv_messenger_t; @@ -50,17 +50,17 @@ bool CachingHTTPFileSource::hasLoop() { } void CachingHTTPFileSource::setBase(const std::string &value) { - assert(thread_id == std::this_thread::get_id()); + assert(std::this_thread::get_id() == threadId); base = value; } const std::string &CachingHTTPFileSource::getBase() const { - assert(thread_id == std::this_thread::get_id()); + assert(std::this_thread::get_id() == threadId); return base; } std::unique_ptr CachingHTTPFileSource::request(ResourceType type, const std::string &url) { - assert(thread_id == std::this_thread::get_id()); + assert(std::this_thread::get_id() == threadId); // Make URL absolute. const std::string absoluteURL = [&]() -> std::string { @@ -97,7 +97,7 @@ std::unique_ptr CachingHTTPFileSource::request(ResourceType type, const } void CachingHTTPFileSource::prepare(std::function fn) { - if (thread_id == std::this_thread::get_id()) { + if (std::this_thread::get_id() == threadId) { fn(); } else { uv_messenger_send(queue, new std::function(std::move(fn))); @@ -105,7 +105,7 @@ void CachingHTTPFileSource::prepare(std::function fn) { } void CachingHTTPFileSource::retryAllPending() { - assert(thread_id == std::this_thread::get_id()); + assert(std::this_thread::get_id() == threadId); util::ptr req; for (const std::pair> &pair : pending) { diff --git a/src/map/map.cpp b/src/map/map.cpp index 4880bfdce..7e16f9ba7 100644 --- a/src/map/map.cpp +++ b/src/map/map.cpp @@ -133,13 +133,8 @@ 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 diff --git a/src/storage/asset_request.cpp b/src/storage/asset_request.cpp index 7063f7131..e4684b10f 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(uv_thread_self() == threadId); + assert(std::this_thread::get_id() == threadId); if (ptr) { ptr->cancel(); @@ -30,7 +30,7 @@ void AssetRequest::cancel() { } AssetRequest::~AssetRequest() { - assert(uv_thread_self() == threadId); + assert(std::this_thread::get_id() == threadId); cancel(); } diff --git a/src/storage/asset_request_baton.cpp b/src/storage/asset_request_baton.cpp index cd4720b37..00382f21c 100644 --- a/src/storage/asset_request_baton.cpp +++ b/src/storage/asset_request_baton.cpp @@ -4,12 +4,10 @@ #include #include -#include - namespace mbgl { AssetRequestBaton::AssetRequestBaton(AssetRequest *request_, const std::string &path_, uv_loop_t *loop) - : threadId(uv_thread_self()), + : threadId(std::this_thread::get_id()), request(request_), path(path_) { @@ -25,7 +23,7 @@ void AssetRequestBaton::cancel() { } void AssetRequestBaton::notify_error(AssetRequestBaton *ptr, const int code, const char *message) { - assert(uv_thread_self() == ptr->threadId); + assert(std::this_thread::get_id() == ptr->threadId); if (ptr->request && !ptr->canceled) { ptr->request->response = std::unique_ptr(new Response); @@ -36,7 +34,7 @@ void AssetRequestBaton::notify_error(AssetRequestBaton *ptr, const int code, con } void AssetRequestBaton::cleanup(AssetRequestBaton *ptr) { - assert(uv_thread_self() == ptr->threadId); + 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 766248405..57e6c260e 100644 --- a/src/storage/http_request.cpp +++ b/src/storage/http_request.cpp @@ -22,13 +22,7 @@ struct CacheRequestBaton { }; HTTPRequest::HTTPRequest(ResourceType type_, const std::string &path_, uv_loop_t *loop_, util::ptr 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 + : BaseRequest(path_), threadId(std::this_thread::get_id()), loop(loop_), store(store_), type(type_) { if (store) { startCacheRequest(); } else { @@ -37,32 +31,24 @@ 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 + assert(std::this_thread::get_id() == threadId); - cache_baton = new CacheRequestBaton; - cache_baton->request = this; - cache_baton->path = path; - cache_baton->store = store; + cacheBaton = new CacheRequestBaton; + cacheBaton->request = this; + cacheBaton->path = path; + cacheBaton->store = store; store->get(path, [](std::unique_ptr &&response_, void *ptr) { // Wrap in a unique_ptr, so it'll always get auto-destructed. std::unique_ptr baton((CacheRequestBaton *)ptr); if (baton->request) { - baton->request->cache_baton = nullptr; + baton->request->cacheBaton = nullptr; baton->request->handleCacheResponse(std::move(response_)); } - }, cache_baton); + }, cacheBaton); } void HTTPRequest::handleCacheResponse(std::unique_ptr &&res) { -<<<<<<< HEAD - assert(uv_thread_self() == threadId); -======= - assert(std::this_thread::get_id() == thread_id); ->>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b + assert(std::this_thread::get_id() == threadId); if (res) { // This entry was stored in the cache. Now determine if we need to revalidate. @@ -83,13 +69,8 @@ void HTTPRequest::handleCacheResponse(std::unique_ptr &&res) { } void HTTPRequest::startHTTPRequest(std::unique_ptr &&res) { -<<<<<<< HEAD - assert(uv_thread_self() == threadId); + assert(std::this_thread::get_id() == threadId); assert(!httpBaton); -======= - assert(std::this_thread::get_id() == thread_id); - assert(!http_baton); ->>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b httpBaton = std::make_shared(path); httpBaton->request = this; @@ -124,13 +105,8 @@ void HTTPRequest::startHTTPRequest(std::unique_ptr &&res) { void HTTPRequest::handleHTTPResponse(HTTPResponseType responseType, std::unique_ptr &&res) { -<<<<<<< HEAD - assert(uv_thread_self() == threadId); + assert(std::this_thread::get_id() == threadId); assert(!httpBaton); -======= - assert(std::this_thread::get_id() == thread_id); - assert(!http_baton); ->>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b assert(!response); switch (responseType) { @@ -217,105 +193,76 @@ void HTTPRequest::handleHTTPResponse(HTTPResponseType responseType, std::unique_ using RetryBaton = std::pair>; void HTTPRequest::retryHTTPRequest(std::unique_ptr &&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); - backoff_timer->data = new RetryBaton(this, std::move(res)); + assert(std::this_thread::get_id() == threadId); + assert(!backoffTimer); + backoffTimer = new uv_timer_t(); + uv_timer_init(loop, backoffTimer); + backoffTimer->data = new RetryBaton(this, std::move(res)); #if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10 - uv_timer_start(backoff_timer, [](uv_timer_t *timer, int) { + uv_timer_start(backoffTimer, [](uv_timer_t *timer, int) { #else - uv_timer_start(backoff_timer, [](uv_timer_t *timer) { + uv_timer_start(backoffTimer, [](uv_timer_t *timer) { #endif std::unique_ptr pair { static_cast(timer->data) }; pair->first->startHTTPRequest(std::move(pair->second)); - pair->first->backoff_timer = nullptr; + pair->first->backoffTimer = nullptr; uv_timer_stop(timer); uv_close((uv_handle_t *)timer, [](uv_handle_t *handle) { delete (uv_timer_t *)handle; }); }, timeout, 0); } void HTTPRequest::removeHTTPBaton() { -<<<<<<< HEAD - assert(uv_thread_self() == threadId); + assert(std::this_thread::get_id() == 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) { + assert(std::this_thread::get_id() == threadId); + if (cacheBaton) { // 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 // null is sufficient. // Note: We don't manually delete the CacheRequestBaton since it'll be deleted by the // callback. - cache_baton->request = nullptr; - cache_baton = nullptr; + cacheBaton->request = nullptr; + cacheBaton = nullptr; } } void HTTPRequest::removeBackoffTimer() { -<<<<<<< HEAD - assert(uv_thread_self() == threadId); -======= - assert(std::this_thread::get_id() == thread_id); ->>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b - if (backoff_timer) { - delete static_cast(backoff_timer->data); - uv_timer_stop(backoff_timer); - uv_close((uv_handle_t *)backoff_timer, [](uv_handle_t *handle) { delete (uv_timer_t *)handle; }); - backoff_timer = nullptr; + assert(std::this_thread::get_id() == threadId); + if (backoffTimer) { + delete static_cast(backoffTimer->data); + uv_timer_stop(backoffTimer); + uv_close((uv_handle_t *)backoffTimer, [](uv_handle_t *handle) { delete (uv_timer_t *)handle; }); + backoffTimer = nullptr; } } 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) { + assert(std::this_thread::get_id() == threadId); + if (!cacheBaton && !httpBaton) { + if (backoffTimer) { // Retry immediately. - uv_timer_stop(backoff_timer); - std::unique_ptr pair { static_cast(backoff_timer->data) }; + uv_timer_stop(backoffTimer); + std::unique_ptr pair { static_cast(backoffTimer->data) }; assert(pair->first == this); startHTTPRequest(std::move(pair->second)); - uv_close((uv_handle_t *)backoff_timer, [](uv_handle_t *handle) { delete (uv_timer_t *)handle; }); - backoff_timer = nullptr; + uv_close((uv_handle_t *)backoffTimer, [](uv_handle_t *handle) { delete (uv_timer_t *)handle; }); + backoffTimer = nullptr; } else { - assert(!"We should always have a backoff_timer when there are no batons"); + assert(!"We should always have a backoffTimer when there are no batons"); } } } void HTTPRequest::cancel() { -<<<<<<< HEAD - assert(uv_thread_self() == threadId); -======= - assert(std::this_thread::get_id() == thread_id); ->>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b + assert(std::this_thread::get_id() == threadId); removeCacheBaton(); removeHTTPBaton(); removeBackoffTimer(); @@ -324,11 +271,7 @@ void HTTPRequest::cancel() { HTTPRequest::~HTTPRequest() { -<<<<<<< HEAD - assert(uv_thread_self() == threadId); -======= - assert(std::this_thread::get_id() == thread_id); ->>>>>>> 57249ca32c7b0684be36f5195d4967e6517fe75b + assert(std::this_thread::get_id() == threadId); cancel(); } diff --git a/src/storage/http_request_baton.cpp b/src/storage/http_request_baton.cpp index 7102c20e1..d781a3bdf 100644 --- a/src/storage/http_request_baton.cpp +++ b/src/storage/http_request_baton.cpp @@ -3,11 +3,7 @@ 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(const std::string &path_) : threadId(std::this_thread::get_id()), path(path_) { } HTTPRequestBaton::~HTTPRequestBaton() {