Fixup after merge
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -3,13 +3,16 @@
|
||||
|
||||
#include <mbgl/storage/asset_request.hpp>
|
||||
#include <mbgl/util/uv.hpp>
|
||||
#include <thread>
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
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<uv::async> asyncRun;
|
||||
std::string path;
|
||||
|
||||
@@ -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<HTTPRequestBaton> httpBaton;
|
||||
uv_timer_t *backoff_timer = nullptr;
|
||||
uv_timer_t *backoffTimer = nullptr;
|
||||
util::ptr<SQLiteStore> store;
|
||||
const ResourceType type;
|
||||
uint8_t attempts = 0;
|
||||
|
||||
@@ -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 <zip.h>
|
||||
#include <uv.h>
|
||||
|
||||
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
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
#include <mbgl/storage/asset_request.hpp>
|
||||
#include <mbgl/storage/response.hpp>
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
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
|
||||
|
||||
@@ -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<SQLiteStore>(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<Request> 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<Request> CachingHTTPFileSource::request(ResourceType type, const
|
||||
}
|
||||
|
||||
void CachingHTTPFileSource::prepare(std::function<void()> 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<void()>(std::move(fn)));
|
||||
@@ -105,7 +105,7 @@ void CachingHTTPFileSource::prepare(std::function<void()> fn) {
|
||||
}
|
||||
|
||||
void CachingHTTPFileSource::retryAllPending() {
|
||||
assert(thread_id == std::this_thread::get_id());
|
||||
assert(std::this_thread::get_id() == threadId);
|
||||
|
||||
util::ptr<BaseRequest> req;
|
||||
for (const std::pair<std::string, std::weak_ptr<BaseRequest>> &pair : pending) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,12 +4,10 @@
|
||||
#include <mbgl/util/std.hpp>
|
||||
#include <mbgl/util/uv_detail.hpp>
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
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<Response>(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;
|
||||
|
||||
@@ -22,13 +22,7 @@ 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
|
||||
: 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> &&response_, void *ptr) {
|
||||
// Wrap in a unique_ptr, so it'll always get auto-destructed.
|
||||
std::unique_ptr<CacheRequestBaton> 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<Response> &&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<Response> &&res) {
|
||||
}
|
||||
|
||||
void HTTPRequest::startHTTPRequest(std::unique_ptr<Response> &&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<HTTPRequestBaton>(path);
|
||||
httpBaton->request = this;
|
||||
@@ -124,13 +105,8 @@ 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(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<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);
|
||||
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<RetryBaton> pair { static_cast<RetryBaton *>(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<RetryBaton *>(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<RetryBaton *>(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<RetryBaton> pair { static_cast<RetryBaton *>(backoff_timer->data) };
|
||||
uv_timer_stop(backoffTimer);
|
||||
std::unique_ptr<RetryBaton> pair { static_cast<RetryBaton *>(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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user