From: djsollen@google.com Date: Mon, 15 Oct 2012 16:03:41 +0000 (+0000) Subject: Avoid deadlock in SkGetFallbackFamilyNameForChar(). X-Git-Tag: submit/tizen/20180928.044319~14567 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=77465f9c801401f614870b5243869f4cf17346dd;p=platform%2Fupstream%2FlibSkiaSharp.git Avoid deadlock in SkGetFallbackFamilyNameForChar(). The deaklock happened when SkFontHost::CreateTypefaceFromStream() is called indirectly from SkGetFallbackFamilyNameForChar(). This commits a change that was submitted for review by... wangxianzhu1 @ https://codereview.appspot.com/6654051/ Review URL: https://codereview.appspot.com/6690044 git-svn-id: http://skia.googlecode.com/svn/trunk@5956 2bbb7eff-a529-9590-31e7-b0007b416f81 --- diff --git a/src/ports/SkFontHost_android.cpp b/src/ports/SkFontHost_android.cpp index 9f1bd56c67..d46c897ca5 100644 --- a/src/ports/SkFontHost_android.cpp +++ b/src/ports/SkFontHost_android.cpp @@ -1005,6 +1005,7 @@ static const int gFBScriptInfoCount = sizeof(gFBScriptInfo) / sizeof(FBScriptInf // ensure that if any value is added to the public enum it is also added here SK_COMPILE_ASSERT(gFBScriptInfoCount == kFallbackScriptNumber, FBScript_count_mismatch); +// this function can't be called if the gFamilyHeadAndNameListMutex is already locked static bool typefaceContainsChar(SkTypeface* face, SkUnichar uni) { SkPaint paint; paint.setTypeface(face); @@ -1015,11 +1016,16 @@ static bool typefaceContainsChar(SkTypeface* face, SkUnichar uni) { return glyphID != 0; } +// this function can't be called if the gFamilyHeadAndNameListMutex is already locked static SkTypeface* findFallbackTypefaceForChar(SkUnichar uni) { SkASSERT(gFallbackFonts); const uint32_t* list = gFallbackFonts; for (int i = 0; list[i] != 0; i++) { - SkTypeface* face = find_from_uniqueID(list[i]); + SkTypeface* face; + { + SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); + face = find_from_uniqueID(list[i]); + } if (typefaceContainsChar(face, uni)) { return face; } @@ -1027,6 +1033,7 @@ static SkTypeface* findFallbackTypefaceForChar(SkUnichar uni) { return 0; } +// this function can't be called if the gFamilyHeadAndNameListMutex is already locked static SkFontID findFallbackFontIDForChar(SkUnichar uni, SkTypeface::Style style) { const SkTypeface* tf = findFallbackTypefaceForChar(uni); if (!tf) { @@ -1107,13 +1114,16 @@ FallbackScripts SkGetFallbackScriptFromID(const char* id) { SkTypeface* SkCreateFallbackTypefaceForChar(SkUnichar uni, SkTypeface::Style style) { - SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); - load_system_fonts(); + { + SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); + load_system_fonts(); + } SkTypeface* tf = findFallbackTypefaceForChar(uni); if (!tf) { return NULL; } + SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); tf = find_typeface(tf, style); // we ref(), since the semantic is to return a new instance tf->ref(); @@ -1122,13 +1132,16 @@ SkTypeface* SkCreateFallbackTypefaceForChar(SkUnichar uni, bool SkGetFallbackFamilyNameForChar(SkUnichar uni, SkString* name) { SkASSERT(name); - SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); - load_system_fonts(); + { + SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); + load_system_fonts(); + } const SkTypeface* tf = findFallbackTypefaceForChar(uni); if (!tf) { return false; } + SkAutoMutexAcquire ac(gFamilyHeadAndNameListMutex); name->set(find_family_name(tf)); return true; }