From b0c89e7f44a9a917e4d40ab3b7a8f57465ccdddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20K=C3=A4fer?= Date: Tue, 19 May 2015 15:04:02 +0200 Subject: [PATCH] extend the FontStack lock to returned values --- src/mbgl/renderer/symbol_bucket.cpp | 4 ++-- src/mbgl/text/glyph_store.cpp | 8 ++++---- src/mbgl/text/glyph_store.hpp | 3 ++- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/mbgl/renderer/symbol_bucket.cpp b/src/mbgl/renderer/symbol_bucket.cpp index 4d957a1e5..d984752f1 100644 --- a/src/mbgl/renderer/symbol_bucket.cpp +++ b/src/mbgl/renderer/symbol_bucket.cpp @@ -190,7 +190,7 @@ void SymbolBucket::addFeatures(uintptr_t tileUID, if (layout.text.justify == TextJustifyType::Right) justify = 1; else if (layout.text.justify == TextJustifyType::Left) justify = 0; - auto* fontStack = glyphStore.getFontStack(layout.text.font); + auto fontStack = glyphStore.getFontStack(layout.text.font); for (const auto& feature : features) { if (!feature.geometry.size()) continue; @@ -214,7 +214,7 @@ void SymbolBucket::addFeatures(uintptr_t tileUID, // Add the glyphs we need for this label to the glyph atlas. if (shaping.size()) { - glyphAtlas.addGlyphs(tileUID, feature.label, layout.text.font, *fontStack, face); + glyphAtlas.addGlyphs(tileUID, feature.label, layout.text.font, **fontStack, face); } } diff --git a/src/mbgl/text/glyph_store.cpp b/src/mbgl/text/glyph_store.cpp index 10723af1a..031720325 100644 --- a/src/mbgl/text/glyph_store.cpp +++ b/src/mbgl/text/glyph_store.cpp @@ -297,15 +297,15 @@ FontStack* GlyphStore::createFontStack(const std::string &fontStack) { return stack_it->second.get(); } -FontStack* GlyphStore::getFontStack(const std::string &fontStack) { - std::lock_guard lock(stacksMutex); +util::exclusive GlyphStore::getFontStack(const std::string &fontStack) { + auto lock = util::make_unique>(stacksMutex); const auto& stack_it = stacks.find(fontStack); if (stack_it == stacks.end()) { - return nullptr; + return { nullptr, nullptr }; } - return stack_it->second.get(); + return { stack_it->second.get(), std::move(lock) }; } void GlyphStore::setObserver(Observer* observer_) { diff --git a/src/mbgl/text/glyph_store.hpp b/src/mbgl/text/glyph_store.hpp index efa848dd0..a42130855 100644 --- a/src/mbgl/text/glyph_store.hpp +++ b/src/mbgl/text/glyph_store.hpp @@ -4,6 +4,7 @@ #include #include #include +#include #include #include @@ -104,7 +105,7 @@ public: // GlyphRanges are already available, and thus, no request is performed. bool requestGlyphRangesIfNeeded(const std::string &fontStack, const std::set &glyphRanges); - FontStack* getFontStack(const std::string &fontStack); + util::exclusive getFontStack(const std::string &fontStack); void setURL(const std::string &url);