summaryrefslogtreecommitdiff
path: root/src/mbgl/storage
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2015-05-13 11:50:16 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2015-05-13 13:54:16 -0700
commite6eb6c7fe421abe1fa6d2ca0934847cf326fa222 (patch)
tree0b15129a3b500d1163c0608e47cf99b24b09a237 /src/mbgl/storage
parent386be7c0faf20220f1e25b1a29f478519d1e2aa9 (diff)
downloadqtlocation-mapboxgl-e6eb6c7fe421abe1fa6d2ca0934847cf326fa222.tar.gz
Use uv::async
Diffstat (limited to 'src/mbgl/storage')
-rw-r--r--src/mbgl/storage/request.cpp38
1 files changed, 7 insertions, 31 deletions
diff --git a/src/mbgl/storage/request.cpp b/src/mbgl/storage/request.cpp
index 53a882f2a6..a6d845ce4a 100644
--- a/src/mbgl/storage/request.cpp
+++ b/src/mbgl/storage/request.cpp
@@ -5,9 +5,7 @@
#include <mbgl/util/util.hpp>
#include <mbgl/util/std.hpp>
-#include <mbgl/util/uv.hpp>
-
-#include <uv.h>
+#include <mbgl/util/uv_detail.hpp>
#include <cassert>
#include <functional>
@@ -18,18 +16,9 @@ struct Request::Canceled { std::mutex mutex; bool confirmed = false; };
// Note: This requires that loop is running in the current thread (or not yet running).
Request::Request(const Resource &resource_, uv_loop_t *loop, Callback callback_)
- : callback(callback_), resource(resource_) {
- // 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) {
- async = new uv_async_t;
- async->data = this;
-#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
- uv_async_init(loop, async, [](uv_async_t *a, int) { reinterpret_cast<Request *>(a->data)->notifyCallback(); });
-#else
- uv_async_init(loop, async, [](uv_async_t *a) { reinterpret_cast<Request *>(a->data)->notifyCallback(); });
-#endif
- }
+ : async(util::make_unique<uv::async>(loop, [this] { notifyCallback(); })),
+ callback(callback_),
+ resource(resource_) {
}
// Called in the originating thread.
@@ -59,27 +48,14 @@ void Request::invoke() {
delete this;
}
-Request::~Request() {
- if (async) {
- uv_close(reinterpret_cast<uv_handle_t*>(async), [](uv_handle_t* handle) {
- delete reinterpret_cast<uv_async_t*>(handle);
- });
- }
-}
+Request::~Request() = default;
// Called in the FileSource thread.
void Request::notify(const std::shared_ptr<const Response> &response_) {
assert(!response);
response = response_;
assert(response);
-
- if (async) {
- uv_async_send(async);
- } else {
- // This request is not cancelable. This means that the callback will be executed in an
- // arbitrary thread (== FileSource thread).
- invoke();
- }
+ async->send();
}
// Called in the originating thread.
@@ -97,7 +73,7 @@ void Request::destruct() {
assert(canceled);
std::unique_lock<std::mutex> lock(canceled->mutex);
canceled->confirmed = true;
- uv_async_send(async);
+ async->send();
// after this method returns, the FileSource thread has no knowledge of
// this object anymore.
}