diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2015-02-11 14:03:44 -0800 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2015-03-06 15:42:34 +0100 |
commit | c30bb1a9f80a7a772578d8742e122c013a56202d (patch) | |
tree | 177f3ff07634b655d65ef18872aae2c2241a6247 /src/mbgl/text/glyph_store.cpp | |
parent | e00bae4f1c9fed201dd01f641f7849d4178e0e7c (diff) | |
download | qtlocation-mapboxgl-c30bb1a9f80a7a772578d8742e122c013a56202d.tar.gz |
add more locking around GlyphStore and FontStack
this is a stopgap until we have a solution that gives every worker thread their own copy
Diffstat (limited to 'src/mbgl/text/glyph_store.cpp')
-rw-r--r-- | src/mbgl/text/glyph_store.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/mbgl/text/glyph_store.cpp b/src/mbgl/text/glyph_store.cpp index 0d9e70d556..f89f42e909 100644 --- a/src/mbgl/text/glyph_store.cpp +++ b/src/mbgl/text/glyph_store.cpp @@ -223,7 +223,7 @@ void GlyphPBF::parse(FontStack &stack) { data.clear(); } -GlyphStore::GlyphStore(FileSource& fileSource_) : fileSource(fileSource_) {} +GlyphStore::GlyphStore(FileSource& fileSource_) : fileSource(fileSource_), mtx(util::make_unique<uv::mutex>()) {} void GlyphStore::setURL(const std::string &url) { glyphURL = url; @@ -237,15 +237,14 @@ void GlyphStore::waitForGlyphRanges(const std::string &fontStack, const std::set return; } - FontStack *stack = nullptr; + uv::exclusive<FontStack> stack(mtx); std::vector<std::shared_future<GlyphPBF &>> futures; futures.reserve(glyphRanges.size()); { - std::lock_guard<std::mutex> lock(mtx); auto &rangeSets = ranges[fontStack]; - stack = &createFontStack(fontStack); + stack << createFontStack(fontStack); // Attempt to load the glyph range. If the GlyphSet already exists, we are getting back // the same shared_future. @@ -258,7 +257,7 @@ void GlyphStore::waitForGlyphRanges(const std::string &fontStack, const std::set // When we get a result (or the GlyphSet is aready loaded), we are attempting to parse the // GlyphSet. for (std::shared_future<GlyphPBF &> &future : futures) { - future.get().parse(*stack); + future.get().parse(stack); } } @@ -277,12 +276,14 @@ FontStack &GlyphStore::createFontStack(const std::string &fontStack) { if (stack_it == stacks.end()) { stack_it = stacks.emplace(fontStack, util::make_unique<FontStack>()).first; } + return *stack_it->second.get(); } -FontStack &GlyphStore::getFontStack(const std::string &fontStack) { - std::lock_guard<std::mutex> lock(mtx); - return createFontStack(fontStack); +uv::exclusive<FontStack> GlyphStore::getFontStack(const std::string &fontStack) { + uv::exclusive<FontStack> stack(mtx); + stack << createFontStack(fontStack); + return stack; } |