code style

This commit is contained in:
Konstantin Käfer
2015-02-13 10:55:22 -08:00
parent aecef6da1a
commit f4e9908045
2 changed files with 27 additions and 27 deletions

View File

@@ -38,8 +38,8 @@ private:
static void cancelCallback(uv_async_t *async);
private:
uv_async_t *notify_async = nullptr;
uv_async_t *destruct_async = nullptr;
uv_async_t *notifyAsync = nullptr;
uv_async_t *destructAsync = nullptr;
Callback callback;
std::shared_ptr<const Response> response;

View File

@@ -18,12 +18,12 @@ Request::Request(const Resource &resource_, uv_loop_t *loop, Callback callback_)
// When there is no loop supplied (== nullptr), the callback will be fired in an arbitrary
// thread (the thread notify() is called from) rather than kicking back to the calling thread.
if (loop) {
notify_async = new uv_async_t;
notify_async->data = nullptr;
notifyAsync = new uv_async_t;
notifyAsync->data = nullptr;
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
uv_async_init(loop, notify_async, [](uv_async_t *async, int) { notifyCallback(async); });
uv_async_init(loop, notifyAsync, [](uv_async_t *async, int) { notifyCallback(async); });
#else
uv_async_init(loop, notify_async, notifyCallback);
uv_async_init(loop, notifyAsync, notifyCallback);
#endif
}
}
@@ -34,7 +34,7 @@ void Request::notifyCallback(uv_async_t *async) {
assert(request);
MBGL_VERIFY_THREAD(request->tid)
if (!request->destruct_async) {
if (!request->destructAsync) {
// Call the callback with the result data. This will also delete this object. We haven't
// created a cancel request, so this is safe since it won't be accessed in the future.
// It is up to the user to not call cancel() on this Request object after the response was
@@ -64,10 +64,10 @@ Request::~Request() {
void Request::notify(const std::shared_ptr<const Response> &response_) {
response = response_;
assert(response);
if (notify_async) {
assert(!notify_async->data);
notify_async->data = this;
uv_async_send(notify_async);
if (notifyAsync) {
assert(!notifyAsync->data);
notifyAsync->data = this;
uv_async_send(notifyAsync);
} else {
// This request is not cancelable. This means that the callback will be executed in an
// arbitrary thread (== FileSource thread).
@@ -77,19 +77,19 @@ void Request::notify(const std::shared_ptr<const Response> &response_) {
void Request::cancel() {
MBGL_VERIFY_THREAD(tid)
assert(notify_async);
assert(!destruct_async);
destruct_async = new uv_async_t;
destruct_async->data = nullptr;
assert(notifyAsync);
assert(!destructAsync);
destructAsync = new uv_async_t;
destructAsync->data = nullptr;
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
uv_async_init(notify_async->loop, destruct_async, [](uv_async_t *async, int) { cancelCallback(async); });
uv_async_init(notifyAsync->loop, destructAsync, [](uv_async_t *async, int) { cancelCallback(async); });
#else
uv_async_init(notify_async->loop, destruct_async, cancelCallback);
uv_async_init(notifyAsync->loop, destructAsync, cancelCallback);
#endif
}
void Request::cancelCallback(uv_async_t *async) {
// The destruct_async will be invoked *after* the notify_async callback has already run.
// The destructAsync will be invoked *after* the notifyAsync callback has already run.
auto request = reinterpret_cast<Request *>(async->data);
uv::close(async);
assert(request);
@@ -100,20 +100,20 @@ void Request::cancelCallback(uv_async_t *async) {
// This gets called from the FileSource thread, and will only ever be invoked after cancel() was called
// in the original requesting thread.
void Request::destruct() {
assert(notify_async);
assert(destruct_async);
assert(notifyAsync);
assert(destructAsync);
if (!notify_async->data) {
if (!notifyAsync->data) {
// The async hasn't been triggered yet, but we need to so that it'll close the handle. The
// callback will not delete this object since we have a destruct_async handle as well.
notify_async->data = this;
uv_async_send(notify_async);
// callback will not delete this object since we have a destructAsync handle as well.
notifyAsync->data = this;
uv_async_send(notifyAsync);
}
// This will finally destruct this object.
assert(!destruct_async->data);
destruct_async->data = this;
uv_async_send(destruct_async);
assert(!destructAsync->data);
destructAsync->data = this;
uv_async_send(destructAsync);
}
}