From 13ba4e478d19001ddb6828bd1fd8fbc1e0cb208f Mon Sep 17 00:00:00 2001 From: Raph Levien Date: Wed, 12 Sep 2012 15:15:51 -0700 Subject: 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 --- core/jni/android/graphics/TextLayoutCache.cpp | 7 ++++--- core/jni/android/graphics/TextLayoutCache.h | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/core/jni/android/graphics/TextLayoutCache.cpp b/core/jni/android/graphics/TextLayoutCache.cpp index 7abfcf1efaa5..8032ed81b65b 100644 --- a/core/jni/android/graphics/TextLayoutCache.cpp +++ b/core/jni/android/graphics/TextLayoutCache.cpp @@ -78,8 +78,10 @@ void TextLayoutCache::operator()(TextLayoutCacheKey& text, sp& /* * Cache clearing */ -void TextLayoutCache::clear() { +void TextLayoutCache::purgeCaches() { + AutoMutex _l(mLock); mCache.clear(); + mShaper->purgeCaches(); } /* @@ -965,8 +967,7 @@ sp TextLayoutEngine::getValue(const SkPaint* paint, const jchar void TextLayoutEngine::purgeCaches() { #if USE_TEXT_LAYOUT_CACHE - mTextLayoutCache->clear(); - mShaper->purgeCaches(); + mTextLayoutCache->purgeCaches(); #if DEBUG_GLYPHS ALOGD("Purged TextLayoutEngine caches"); #endif diff --git a/core/jni/android/graphics/TextLayoutCache.h b/core/jni/android/graphics/TextLayoutCache.h index 64b33a0a2c3d..1f4e22c8274f 100644 --- a/core/jni/android/graphics/TextLayoutCache.h +++ b/core/jni/android/graphics/TextLayoutCache.h @@ -276,7 +276,7 @@ public: /** * Clear the cache */ - void clear(); + void purgeCaches(); private: TextLayoutShaper* mShaper; -- cgit v1.2.3-59-g8ed1b