From b09df7acb5139e50b3de7bfcb7e92909ba9c3a56 Mon Sep 17 00:00:00 2001 From: "Thiago Marcos P. Santos" Date: Fri, 29 May 2015 15:30:50 +0300 Subject: [PATCH] Cleanup the MapContext before the util::Thread destructor The util::Thread will call the stop() method of the MapContext's RunLoop which will wait for the pending tasks tied to it to complete. If we have a request that is timeout'ing, this could mean a really long wait. Instead, we now send a cleanup message that will reset all the attributes first (canceling the pending requests) so the the MapContext gets destructed quickly. --- src/mbgl/map/map.cpp | 1 + src/mbgl/map/map_context.cpp | 5 +++++ src/mbgl/map/map_context.hpp | 2 ++ test/miscellaneous/map_context.cpp | 1 + 4 files changed, 9 insertions(+) diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index 047918930..47c9472d5 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -17,6 +17,7 @@ Map::Map(View& view, FileSource& fileSource, MapMode mode) Map::~Map() { resume(); + context->invoke(&MapContext::cleanup); } void Map::pause() { diff --git a/src/mbgl/map/map_context.cpp b/src/mbgl/map/map_context.cpp index 47a6b3e4b..c349bdd15 100644 --- a/src/mbgl/map/map_context.cpp +++ b/src/mbgl/map/map_context.cpp @@ -36,6 +36,11 @@ MapContext::MapContext(uv_loop_t* loop, View& view_, FileSource& fileSource, Map } MapContext::~MapContext() { + // Make sure we call cleanup() before deleting this object. + assert(!style); +} + +void MapContext::cleanup() { view.notify(); // Explicit resets currently necessary because these abandon resources that need to be diff --git a/src/mbgl/map/map_context.hpp b/src/mbgl/map/map_context.hpp index 889443424..81e757c4c 100644 --- a/src/mbgl/map/map_context.hpp +++ b/src/mbgl/map/map_context.hpp @@ -54,6 +54,8 @@ public: void setSourceTileCacheSize(size_t size); void onLowMemory(); + void cleanup(); + // Style::Observer implementation. void onTileDataChanged() override; void onResourceLoadingFailed(std::exception_ptr error) override; diff --git a/test/miscellaneous/map_context.cpp b/test/miscellaneous/map_context.cpp index ed5192303..15061b122 100644 --- a/test/miscellaneous/map_context.cpp +++ b/test/miscellaneous/map_context.cpp @@ -19,4 +19,5 @@ TEST(MapContext, DoubleStyleLoad) { context.invokeSync(&MapContext::setStyleJSON, "", ""); context.invokeSync(&MapContext::setStyleJSON, "", ""); + context.invokeSync(&MapContext::cleanup); }