Fix debug build
This commit is contained in:
@@ -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> response;
|
||||
|
||||
|
||||
@@ -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<HTTPRequestBaton> http_baton;
|
||||
util::ptr<HTTPRequestBaton> httpBaton;
|
||||
uv_timer_t *backoff_timer = nullptr;
|
||||
util::ptr<SQLiteStore> store;
|
||||
const ResourceType type;
|
||||
@@ -54,4 +54,4 @@ private:
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -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 <zip.h>
|
||||
#include <uv.h>
|
||||
|
||||
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
|
||||
|
||||
@@ -2,10 +2,12 @@
|
||||
#include <mbgl/storage/asset_request.hpp>
|
||||
#include <mbgl/storage/response.hpp>
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
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
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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<Response>(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;
|
||||
|
||||
@@ -19,13 +19,13 @@ void invoke(const std::forward_list<std::unique_ptr<Callback>> &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<BaseRequest> &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<BaseRequest> &re
|
||||
}
|
||||
|
||||
void BaseRequest::remove(Callback *callback) {
|
||||
assert(thread_id == uv_thread_self());
|
||||
assert(uv_thread_self() == threadId);
|
||||
callbacks.remove_if([=](const std::unique_ptr<Callback> &cb) {
|
||||
return cb.get() == callback;
|
||||
});
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ void FileRequestBaton::cancel() {
|
||||
|
||||
void FileRequestBaton::notify_error(uv_fs_t *req) {
|
||||
FileRequestBaton *ptr = reinterpret_cast<FileRequestBaton *>(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<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->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<FileRequestBaton *>(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<FileRequestBaton *>(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<FileRequestBaton *>(req->data)->thread_id == uv_thread_self());
|
||||
assert(reinterpret_cast<FileRequestBaton *>(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<FileRequestBaton *>(req->data);
|
||||
assert(ptr->thread_id == uv_thread_self());
|
||||
assert(ptr->threadId == uv_thread_self());
|
||||
|
||||
if (ptr->request) {
|
||||
ptr->request->ptr = nullptr;
|
||||
|
||||
@@ -22,7 +22,7 @@ struct CacheRequestBaton {
|
||||
};
|
||||
|
||||
HTTPRequest::HTTPRequest(ResourceType type_, const std::string &path_, uv_loop_t *loop_, util::ptr<SQLiteStore> 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<Response> &&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<Response> &&res) {
|
||||
}
|
||||
|
||||
void HTTPRequest::startHTTPRequest(std::unique_ptr<Response> &&res) {
|
||||
assert(uv_thread_self() == thread_id);
|
||||
assert(!http_baton);
|
||||
assert(uv_thread_self() == threadId);
|
||||
assert(!httpBaton);
|
||||
|
||||
http_baton = std::make_shared<HTTPRequestBaton>(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<HTTPRequestBaton>(http_baton);
|
||||
httpBaton = std::make_shared<HTTPRequestBaton>(path);
|
||||
httpBaton->request = this;
|
||||
httpBaton->async = new uv_async_t;
|
||||
httpBaton->response = std::move(res);
|
||||
httpBaton->async->data = new util::ptr<HTTPRequestBaton>(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<HTTPRequestBaton> &baton = *(util::ptr<HTTPRequestBaton> *)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<Response> &&res) {
|
||||
});
|
||||
});
|
||||
attempts++;
|
||||
HTTPRequestBaton::start(http_baton);
|
||||
HTTPRequestBaton::start(httpBaton);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void HTTPRequest::handleHTTPResponse(HTTPResponseType responseType, std::unique_ptr<Response> &&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<HTTPRequest *, std::unique_ptr<Response>>;
|
||||
|
||||
void HTTPRequest::retryHTTPRequest(std::unique_ptr<Response> &&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<Response> &&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<RetryBaton *>(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();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user