summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Shalamov <alexander.shalamov@mapbox.com>2019-05-02 11:40:23 +0200
committerAlexander Shalamov <alexander.shalamov@mapbox.com>2019-05-03 10:01:19 +0300
commitad30ba2cd145846b1c8a6c8bd26b427d48dde60f (patch)
treef960f2c4a1d0d80574a002888246df834796ffd5
parent86b94e30e17af5404ff69c5fef19abc2bc8b6fa1 (diff)
downloadqtlocation-mapboxgl-ad30ba2cd145846b1c8a6c8bd26b427d48dde60f.tar.gz
[core] Guard access to CustomTileLoader's data members with mutex
-rw-r--r--src/mbgl/style/custom_tile_loader.cpp10
-rw-r--r--src/mbgl/style/custom_tile_loader.hpp3
2 files changed, 9 insertions, 4 deletions
diff --git a/src/mbgl/style/custom_tile_loader.cpp b/src/mbgl/style/custom_tile_loader.cpp
index 48fd5ae9e2..a266e60cfc 100644
--- a/src/mbgl/style/custom_tile_loader.cpp
+++ b/src/mbgl/style/custom_tile_loader.cpp
@@ -11,6 +11,7 @@ CustomTileLoader::CustomTileLoader(const TileFunction& fetchTileFn, const TileFu
}
void CustomTileLoader::fetchTile(const OverscaledTileID& tileID, ActorRef<CustomGeometryTile> tileRef) {
+ std::lock_guard<std::mutex> guard(dataMutex);
auto cachedTileData = dataCache.find(tileID.canonical);
if (cachedTileData != dataCache.end()) {
tileRef.invoke(&CustomGeometryTile::setTileData, *(cachedTileData->second));
@@ -34,12 +35,14 @@ void CustomTileLoader::fetchTile(const OverscaledTileID& tileID, ActorRef<Custom
}
void CustomTileLoader::cancelTile(const OverscaledTileID& tileID) {
+ std::lock_guard<std::mutex> guard(dataMutex);
if (tileCallbackMap.find(tileID.canonical) != tileCallbackMap.end()) {
invokeTileCancel(tileID.canonical);
}
}
void CustomTileLoader::removeTile(const OverscaledTileID& tileID) {
+ std::lock_guard<std::mutex> guard(dataMutex);
auto tileCallbacks = tileCallbackMap.find(tileID.canonical);
if (tileCallbacks == tileCallbackMap.end()) return;
for (auto iter = tileCallbacks->second.begin(); iter != tileCallbacks->second.end(); iter++) {
@@ -56,10 +59,10 @@ void CustomTileLoader::removeTile(const OverscaledTileID& tileID) {
}
void CustomTileLoader::setTileData(const CanonicalTileID& tileID, const GeoJSON& data) {
-
+ std::lock_guard<std::mutex> guard(dataMutex);
auto iter = tileCallbackMap.find(tileID);
if (iter == tileCallbackMap.end()) return;
- auto dataPtr = std::make_unique<mapbox::geojson::geojson>(std::move(data));
+ auto dataPtr = std::make_unique<mapbox::geojson::geojson>(data);
for (auto tuple : iter->second) {
auto actor = std::get<2>(tuple);
actor.invoke(&CustomGeometryTile::setTileData, *dataPtr);
@@ -68,6 +71,7 @@ void CustomTileLoader::setTileData(const CanonicalTileID& tileID, const GeoJSON&
}
void CustomTileLoader::invalidateTile(const CanonicalTileID& tileID) {
+ std::lock_guard<std::mutex> guard(dataMutex);
auto tileCallbacks = tileCallbackMap.find(tileID);
if (tileCallbacks == tileCallbackMap.end()) { return; }
for (auto& iter : tileCallbacks->second) {
@@ -80,8 +84,8 @@ void CustomTileLoader::invalidateTile(const CanonicalTileID& tileID) {
}
void CustomTileLoader::invalidateRegion(const LatLngBounds& bounds, Range<uint8_t> ) {
+ std::lock_guard<std::mutex> guard(dataMutex);
std::map<uint8_t, util::TileRange> tileRanges;
-
for (auto& idtuple : tileCallbackMap) {
auto zoom = idtuple.first.z;
auto tileRange = tileRanges.find(zoom);
diff --git a/src/mbgl/style/custom_tile_loader.hpp b/src/mbgl/style/custom_tile_loader.hpp
index 335d8c6143..7d2d5cffe6 100644
--- a/src/mbgl/style/custom_tile_loader.hpp
+++ b/src/mbgl/style/custom_tile_loader.hpp
@@ -6,6 +6,7 @@
#include <mbgl/actor/actor_ref.hpp>
#include <map>
+#include <mutex>
namespace mbgl {
@@ -38,7 +39,7 @@ private:
std::unordered_map<CanonicalTileID, std::vector<OverscaledIDFunctionTuple>> tileCallbackMap;
// Keep around a cache of tile data to serve back for wrapped and over-zooomed tiles
std::map<CanonicalTileID, std::unique_ptr<GeoJSON>> dataCache;
-
+ std::mutex dataMutex;
};
} // namespace style