diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2014-04-30 12:01:26 +0200 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2014-04-30 12:01:26 +0200 |
commit | 1216a061d3e46eae983a38e42e71115e5c9faef6 (patch) | |
tree | 7ddb57f2885072db82657dc56dff64e49e28db76 /common/curl_request.cpp | |
parent | ddc359f006c47e2a503b616d27e22f5d29c13e5b (diff) | |
download | qtlocation-mapboxgl-1216a061d3e46eae983a38e42e71115e5c9faef6.tar.gz |
move to libuv for the rendering loop
Diffstat (limited to 'common/curl_request.cpp')
-rw-r--r-- | common/curl_request.cpp | 25 |
1 files changed, 7 insertions, 18 deletions
diff --git a/common/curl_request.cpp b/common/curl_request.cpp index e00e805786..0702e1e720 100644 --- a/common/curl_request.cpp +++ b/common/curl_request.cpp @@ -88,10 +88,9 @@ static std::queue<CURL *> curl_handle_cache; class CURLRequest : public llmr::platform::Request { public: CURLRequest(const std::string &url, - std::function<void(llmr::platform::Response *)> background_function, - std::function<void()> foreground_callback, + std::function<void(llmr::platform::Response *)> callback, uv_loop_t *loop) - : Request(url, background_function, foreground_callback, loop) {} + : Request(url, callback, loop) {} CURL *curl = nullptr; }; @@ -169,16 +168,7 @@ void curl_perform(uv_poll_t *req, int /*status*/, int events) { // We're currently in the CURL request thread. We're going to schedule a uv_work request // that executes the background function in a threadpool, and tell it to call the // after callback back in the main uv loop. - - uv_work_t *work = new uv_work_t(); - - // We're passing on the pointer we created to the work structure. - // It is going to be deleted in the after_work_cb; - work->data = req; - - // Executes the background_function in a libuv thread pool, and the after_work_cb back - // in the *main* event loop. - uv_queue_work((*req)->loop, work, Request::work_callback, Request::after_work_callback); + (*req)->complete(); CURL *handle = message->easy_handle; remove_curl_handle(handle); @@ -187,6 +177,8 @@ void curl_perform(uv_poll_t *req, int /*status*/, int events) { // be cancelled. ((CURLRequest *)req->get())->curl = nullptr; + // Delete the shared_ptr pointer we created earlier. + delete req; break; } @@ -312,8 +304,6 @@ void async_add_cb(uv_async_t * /*async*/) { continue; } - (*req)->res = std::make_unique<Response>(); - // Obtain a curl handle (and try to reuse existing handles before creating new ones). CURL *handle = nullptr; if (!curl_handle_cache.empty()) { @@ -367,12 +357,11 @@ void thread_init_cb() { std::shared_ptr<platform::Request> platform::request_http(const std::string &url, - std::function<void(Response *)> background_function, - std::function<void()> foreground_callback, + std::function<void(Response *)> callback, uv_loop_t *loop) { using namespace request; init_thread_once(thread_init_cb); - std::shared_ptr<CURLRequest> req = std::make_shared<CURLRequest>(url, background_function, foreground_callback, loop); + std::shared_ptr<CURLRequest> req = std::make_shared<CURLRequest>(url, callback, loop); // Note that we are creating a new shared_ptr pointer(!) because the lockless queue can't store // objects with nontrivial destructors. We have to make absolutely sure that we manually delete |