Skip to content

Commit 13ba4e4

Browse files
committed
Fix for b7155617 race condition in TextLayoutCache.cpp
There was the possibility for a race between clearing the caches and using fonts. This patch simply protects both under the same mLock held by the TextLayoutCache object. Change-Id: Ib366e16a9a9ba702a46bc078d1bc0602713991e5
1 parent 753e128 commit 13ba4e4

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

core/jni/android/graphics/TextLayoutCache.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,10 @@ void TextLayoutCache::operator()(TextLayoutCacheKey& text, sp<TextLayoutValue>&
7878
/*
7979
* Cache clearing
8080
*/
81-
void TextLayoutCache::clear() {
81+
void TextLayoutCache::purgeCaches() {
82+
AutoMutex _l(mLock);
8283
mCache.clear();
84+
mShaper->purgeCaches();
8385
}
8486

8587
/*
@@ -965,8 +967,7 @@ sp<TextLayoutValue> TextLayoutEngine::getValue(const SkPaint* paint, const jchar
965967

966968
void TextLayoutEngine::purgeCaches() {
967969
#if USE_TEXT_LAYOUT_CACHE
968-
mTextLayoutCache->clear();
969-
mShaper->purgeCaches();
970+
mTextLayoutCache->purgeCaches();
970971
#if DEBUG_GLYPHS
971972
ALOGD("Purged TextLayoutEngine caches");
972973
#endif

core/jni/android/graphics/TextLayoutCache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class TextLayoutCache : private OnEntryRemoved<TextLayoutCacheKey, sp<TextLayout
276276
/**
277277
* Clear the cache
278278
*/
279-
void clear();
279+
void purgeCaches();
280280

281281
private:
282282
TextLayoutShaper* mShaper;

0 commit comments

Comments
 (0)