summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2014-12-04 12:09:27 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2014-12-04 15:26:54 -0800
commit36500b9f957dec5336cb080784e6099408cf6af8 (patch)
tree29e5d5363932f683674affe8e967227fa6c2f08d
parent16fe8e64c4d47ac35fa6dd594342d3a265af358b (diff)
downloadqtlocation-mapboxgl-36500b9f957dec5336cb080784e6099408cf6af8.tar.gz
Add CachingHTTPFileSource::clearLoop()
So loop state can be cleaned up in the appropriate thread. This is a hack; loop needs to be externalized from Map. Fixes #686
-rw-r--r--include/mbgl/storage/caching_http_file_source.hpp1
-rw-r--r--include/mbgl/storage/file_source.hpp3
-rw-r--r--src/mbgl/map/map.cpp7
-rw-r--r--src/mbgl/storage/caching_http_file_source.cpp35
4 files changed, 27 insertions, 19 deletions
diff --git a/include/mbgl/storage/caching_http_file_source.hpp b/include/mbgl/storage/caching_http_file_source.hpp
index 403db31838..f566acf49e 100644
--- a/include/mbgl/storage/caching_http_file_source.hpp
+++ b/include/mbgl/storage/caching_http_file_source.hpp
@@ -21,6 +21,7 @@ public:
// Stores and checks the libuv loop for requests
void setLoop(uv_loop_t*);
bool hasLoop();
+ void clearLoop();
// Stores and retrieves the base path/URL for relative requests
void setBase(const std::string &value);
diff --git a/include/mbgl/storage/file_source.hpp b/include/mbgl/storage/file_source.hpp
index c8f6217877..69a0060f6a 100644
--- a/include/mbgl/storage/file_source.hpp
+++ b/include/mbgl/storage/file_source.hpp
@@ -16,8 +16,11 @@ namespace mbgl {
class FileSource : public util::noncopyable {
public:
virtual ~FileSource() = default;
+
virtual void setLoop(uv_loop_t*) = 0;
virtual bool hasLoop() = 0;
+ virtual void clearLoop() = 0;
+
virtual void setBase(const std::string &value) = 0;
virtual std::unique_ptr<Request> request(ResourceType type, const std::string &url) = 0;
virtual void prepare(std::function<void()> fn) = 0;
diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp
index 1a45284757..2113ba6583 100644
--- a/src/mbgl/map/map.cpp
+++ b/src/mbgl/map/map.cpp
@@ -151,6 +151,8 @@ void Map::start() {
workers.reset();
activeSources.clear();
+ fileSource.clearLoop();
+
// Closes all open handles on the loop. This means that the loop will automatically terminate.
asyncCleanup.reset();
asyncRender.reset();
@@ -310,10 +312,7 @@ void Map::setStyleJSON(std::string newStyleJSON, const std::string &base) {
style = std::make_shared<Style>();
}
style->loadJSON((const uint8_t *)styleJSON.c_str());
- if (!fileSource.hasLoop()) {
- fileSource.setLoop(**loop);
- glyphStore = std::make_shared<GlyphStore>(fileSource);
- }
+ glyphStore = std::make_shared<GlyphStore>(fileSource);
fileSource.setBase(base);
glyphStore->setURL(util::mapbox::normalizeGlyphsURL(style->glyph_url, getAccessToken()));
update();
diff --git a/src/mbgl/storage/caching_http_file_source.cpp b/src/mbgl/storage/caching_http_file_source.cpp
index 64582ba5d4..cf23ca1763 100644
--- a/src/mbgl/storage/caching_http_file_source.cpp
+++ b/src/mbgl/storage/caching_http_file_source.cpp
@@ -13,21 +13,6 @@ CachingHTTPFileSource::CachingHTTPFileSource(const std::string &path_)
: path(path_) {}
CachingHTTPFileSource::~CachingHTTPFileSource() {
- if (hasLoop()) {
- assert(thread_id == std::this_thread::get_id());
- uv_messenger_stop(queue, [](uv_messenger_t *msgr) {
- delete msgr;
- });
-
- util::ptr<BaseRequest> req;
-
- // Send a cancel() message to all requests that we are still holding.
- for (const std::pair<std::string, std::weak_ptr<BaseRequest>> &pair : pending) {
- if ((req = pair.second.lock())) {
- req->cancel();
- }
- }
- }
}
void CachingHTTPFileSource::setLoop(uv_loop_t* loop_) {
@@ -47,6 +32,26 @@ bool CachingHTTPFileSource::hasLoop() {
return loop;
}
+void CachingHTTPFileSource::clearLoop() {
+ assert(thread_id == std::this_thread::get_id());
+ assert(loop);
+
+ uv_messenger_stop(queue, [](uv_messenger_t *msgr) {
+ delete msgr;
+ });
+
+ util::ptr<BaseRequest> req;
+
+ // Send a cancel() message to all requests that we are still holding.
+ for (const std::pair<std::string, std::weak_ptr<BaseRequest>> &pair : pending) {
+ if ((req = pair.second.lock())) {
+ req->cancel();
+ }
+ }
+
+ store.reset();
+}
+
void CachingHTTPFileSource::setBase(const std::string &value) {
assert(thread_id == std::this_thread::get_id());
base = value;