summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorThiago Marcos P. Santos <thiago@mapbox.com>2016-01-20 17:36:25 +0200
committerThiago Marcos P. Santos <thiago@mapbox.com>2016-01-20 19:54:20 +0200
commitadcd0eaaac76305402049c23528f36d30c8a7277 (patch)
tree5cdc54e880bab4d19ebc0464e8681c754675242a /platform
parent55c31493aff4f44939087970b1fc4d9a1edbd72c (diff)
downloadqtlocation-mapboxgl-adcd0eaaac76305402049c23528f36d30c8a7277.tar.gz
[osx] Fix loop closing with pending requests
The main loop will now wait for all the requests to complete before closing. This will make the FileSource on OSX block longer than it should at shutdown.
Diffstat (limited to 'platform')
-rw-r--r--platform/darwin/http_request_nsurl.mm7
1 files changed, 7 insertions, 0 deletions
diff --git a/platform/darwin/http_request_nsurl.mm b/platform/darwin/http_request_nsurl.mm
index 306cf96293..9822c8097e 100644
--- a/platform/darwin/http_request_nsurl.mm
+++ b/platform/darwin/http_request_nsurl.mm
@@ -5,6 +5,7 @@
#include <mbgl/util/async_task.hpp>
#include <mbgl/util/time.hpp>
#include <mbgl/util/parsedate.h>
+#include <mbgl/util/run_loop.hpp>
#import <Foundation/Foundation.h>
@@ -96,6 +97,11 @@ HTTPNSURLRequest::HTTPNSURLRequest(HTTPNSURLContext* context_,
context(context_),
existingResponse(existingResponse_),
async([this] { handleResponse(); }) {
+ // Hold the main loop alive until the request returns. This
+ // is needed because completion handler runs in another
+ // thread and will notify this thread using AsyncTask.
+ util::RunLoop::Get()->ref();
+
@autoreleasepool {
NSURL* url = [NSURL URLWithString:@(url_.c_str())];
if (context->accountType == 0 &&
@@ -129,6 +135,7 @@ HTTPNSURLRequest::HTTPNSURLRequest(HTTPNSURLContext* context_,
}
HTTPNSURLRequest::~HTTPNSURLRequest() {
+ util::RunLoop::Get()->unref();
assert(!task);
}