extend the FontStack lock to returned values

This commit is contained in:
Konstantin Käfer
2015-05-19 15:04:02 +02:00
parent ab3105aac9
commit b0c89e7f44
3 changed files with 8 additions and 7 deletions

View File

@@ -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);
}
}

View File

@@ -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<std::mutex> lock(stacksMutex);
util::exclusive<FontStack> GlyphStore::getFontStack(const std::string &fontStack) {
auto lock = util::make_unique<std::lock_guard<std::mutex>>(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_) {

View File

@@ -4,6 +4,7 @@
#include <mbgl/text/glyph.hpp>
#include <mbgl/util/vec.hpp>
#include <mbgl/util/ptr.hpp>
#include <mbgl/util/exclusive.hpp>
#include <cstdint>
#include <vector>
@@ -104,7 +105,7 @@ public:
// GlyphRanges are already available, and thus, no request is performed.
bool requestGlyphRangesIfNeeded(const std::string &fontStack, const std::set<GlyphRange> &glyphRanges);
FontStack* getFontStack(const std::string &fontStack);
util::exclusive<FontStack> getFontStack(const std::string &fontStack);
void setURL(const std::string &url);