From: bungeman Date: Fri, 29 Apr 2016 22:05:02 +0000 (-0700) Subject: Fix race in SkTypeface_FreeType::onCountGlyphs. X-Git-Tag: accepted/tizen/5.0/unified/20181102.025319~129^2~720 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=572f879b6163e1a4fb790a7f63401a6cf0ade1d2;p=platform%2Fupstream%2FlibSkiaSharp.git Fix race in SkTypeface_FreeType::onCountGlyphs. Found by TSAN. This makes the operation slightly slower, but it is not on any user's hot path. BUG=skia:5238 Review-Url: https://codereview.chromium.org/1940613002 --- diff --git a/src/ports/SkFontHost_FreeType.cpp b/src/ports/SkFontHost_FreeType.cpp index 82648c3..b53364e 100644 --- a/src/ports/SkFontHost_FreeType.cpp +++ b/src/ports/SkFontHost_FreeType.cpp @@ -1526,14 +1526,9 @@ int SkTypeface_FreeType::onCharsToGlyphs(const void* chars, Encoding encoding, } int SkTypeface_FreeType::onCountGlyphs() const { - // we cache this value, using -1 as a sentinel for "not computed" - if (fGlyphCount < 0) { - AutoFTAccess fta(this); - FT_Face face = fta.face(); - // if the face failed, we still assign a non-negative value - fGlyphCount = face ? face->num_glyphs : 0; - } - return fGlyphCount; + AutoFTAccess fta(this); + FT_Face face = fta.face(); + return face ? face->num_glyphs : 0; } SkTypeface::LocalizedStrings* SkTypeface_FreeType::onCreateFamilyNameIterator() const { diff --git a/src/ports/SkFontHost_FreeType_common.h b/src/ports/SkFontHost_FreeType_common.h index 8c13a80..6d050cd 100644 --- a/src/ports/SkFontHost_FreeType_common.h +++ b/src/ports/SkFontHost_FreeType_common.h @@ -73,7 +73,6 @@ public: protected: SkTypeface_FreeType(const SkFontStyle& style, SkFontID uniqueID, bool isFixedPitch) : INHERITED(style, uniqueID, isFixedPitch) - , fGlyphCount(-1) {} virtual SkScalerContext* onCreateScalerContext(const SkScalerContextEffects&, @@ -95,8 +94,6 @@ protected: size_t length, void* data) const override; private: - mutable int fGlyphCount; - typedef SkTypeface INHERITED; };