diff options
author | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2020-02-27 11:46:17 +0200 |
---|---|---|
committer | Alexander Shalamov <alexander.shalamov@mapbox.com> | 2020-03-05 17:43:37 +0200 |
commit | 81e116d41a4ea1e3ed0d5e91e06541c3e8855a09 (patch) | |
tree | 79cdee7e5a4ffda6fafcb9f4fce39b5b87682385 /src/mbgl/annotation | |
parent | c5155dcf334a5c5125c065e4447cb8b30989e5e5 (diff) | |
download | qtlocation-mapboxgl-81e116d41a4ea1e3ed0d5e91e06541c3e8855a09.tar.gz |
[core] Use weak annotation manager
Map and renderer / orchestrator should be able to run on a separate threads,
however, legacy AnnotationManager is shared between Map and Renderer, therefore
is not a thread safe. Until AnnotationManager is deprecated and removed from a
code-base, use it only via weak pointers.
Diffstat (limited to 'src/mbgl/annotation')
-rw-r--r-- | src/mbgl/annotation/annotation_manager.hpp | 5 | ||||
-rw-r--r-- | src/mbgl/annotation/annotation_tile.cpp | 10 | ||||
-rw-r--r-- | src/mbgl/annotation/annotation_tile.hpp | 2 |
3 files changed, 14 insertions, 3 deletions
diff --git a/src/mbgl/annotation/annotation_manager.hpp b/src/mbgl/annotation/annotation_manager.hpp index 6c794d7f84..a9389d8ca9 100644 --- a/src/mbgl/annotation/annotation_manager.hpp +++ b/src/mbgl/annotation/annotation_manager.hpp @@ -11,6 +11,8 @@ #include <unordered_set> #include <unordered_map> +#include <mapbox/weak.hpp> + namespace mbgl { class LatLngBounds; @@ -48,6 +50,8 @@ public: static const std::string PointLayerID; static const std::string ShapeLayerID; + mapbox::base::WeakPtr<AnnotationManager> makeWeakPtr() { return weakFactory.makeWeakPtr(); } + private: void add(const AnnotationID&, const SymbolAnnotation&); void add(const AnnotationID&, const LineAnnotation&); @@ -84,6 +88,7 @@ private: ImageMap images; std::unordered_set<AnnotationTile*> tiles; + mapbox::base::WeakPtrFactory<AnnotationManager> weakFactory{this}; }; } // namespace mbgl diff --git a/src/mbgl/annotation/annotation_tile.cpp b/src/mbgl/annotation/annotation_tile.cpp index a410adc95e..69c9f07655 100644 --- a/src/mbgl/annotation/annotation_tile.cpp +++ b/src/mbgl/annotation/annotation_tile.cpp @@ -11,11 +11,17 @@ AnnotationTile::AnnotationTile(const OverscaledTileID& overscaledTileID, const TileParameters& parameters) : GeometryTile(overscaledTileID, AnnotationManager::SourceID, parameters), annotationManager(parameters.annotationManager) { - annotationManager.addTile(*this); + auto guard = annotationManager.lock(); + if (annotationManager) { + annotationManager->addTile(*this); + } } AnnotationTile::~AnnotationTile() { - annotationManager.removeTile(*this); + auto guard = annotationManager.lock(); + if (annotationManager) { + annotationManager->removeTile(*this); + } } class AnnotationTileFeatureData { diff --git a/src/mbgl/annotation/annotation_tile.hpp b/src/mbgl/annotation/annotation_tile.hpp index 741b598a8c..da5fc28cb6 100644 --- a/src/mbgl/annotation/annotation_tile.hpp +++ b/src/mbgl/annotation/annotation_tile.hpp @@ -15,7 +15,7 @@ public: ~AnnotationTile() override; private: - AnnotationManager& annotationManager; + mapbox::base::WeakPtr<AnnotationManager> annotationManager; }; class AnnotationTileFeatureData; |