Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Unified Diff: src/core/SkGlyphCache.cpp

Issue 1210143004: SkGlyphCache_Globals: SkMutex -> SkSpinlock (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: some cleanup Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/core/SkGlyphCache.cpp
diff --git a/src/core/SkGlyphCache.cpp b/src/core/SkGlyphCache.cpp
index ec342275cc6f3c6354eb60d0c16eeebcb8d0767b..23f504de1c25ec7e71814c5651a050315125e0e4 100755
--- a/src/core/SkGlyphCache.cpp
+++ b/src/core/SkGlyphCache.cpp
@@ -425,7 +425,7 @@ size_t SkGlyphCache_Globals::setCacheSizeLimit(size_t newLimit) {
newLimit = minLimit;
}
- SkAutoMutexAcquire ac(fMutex);
+ SkScopedLock<Lock> ac(*fMutex);
size_t prevLimit = fCacheSizeLimit;
fCacheSizeLimit = newLimit;
@@ -438,7 +438,7 @@ int SkGlyphCache_Globals::setCacheCountLimit(int newCount) {
newCount = 0;
}
- SkAutoMutexAcquire ac(fMutex);
+ SkScopedLock<Lock> ac(*fMutex);
int prevCount = fCacheCountLimit;
fCacheCountLimit = newCount;
@@ -447,7 +447,7 @@ int SkGlyphCache_Globals::setCacheCountLimit(int newCount) {
}
void SkGlyphCache_Globals::purgeAll() {
- SkAutoMutexAcquire ac(fMutex);
+ SkScopedLock<Lock> ac(*fMutex);
this->internalPurge(fTotalMemoryUsed);
}
@@ -467,25 +467,25 @@ SkGlyphCache* SkGlyphCache::VisitCache(SkTypeface* typeface,
SkASSERT(desc);
SkGlyphCache_Globals& globals = getGlobals();
- SkAutoMutexAcquire ac(globals.fMutex);
SkGlyphCache* cache;
- bool insideMutex = true;
- globals.validate();
-
- for (cache = globals.internalGetHead(); cache != NULL; cache = cache->fNext) {
- if (cache->fDesc->equals(*desc)) {
- globals.internalDetachCache(cache);
- goto FOUND_IT;
+ {
+ SkScopedLock<SkGlyphCache_Globals::Lock> ac(*globals.fMutex);
+
+ globals.validate();
+
+ for (cache = globals.internalGetHead(); cache != NULL; cache = cache->fNext) {
+ if (cache->fDesc->equals(*desc)) {
+ globals.internalDetachCache(cache);
+ if (!proc(cache, context)) {
+ globals.internalAttachCacheToHead(cache);
+ cache = NULL;
+ }
+ return cache;
+ }
}
}
- /* Release the mutex now, before we create a new entry (which might have
- side-effects like trying to access the cache/mutex (yikes!)
- */
- ac.release(); // release the mutex now
- insideMutex = false; // can't use globals anymore
-
// Check if we can create a scaler-context before creating the glyphcache.
// If not, we may have exhausted OS/font resources, so try purging the
// cache once and try again.
@@ -501,16 +501,10 @@ SkGlyphCache* SkGlyphCache::VisitCache(SkTypeface* typeface,
cache = SkNEW_ARGS(SkGlyphCache, (typeface, desc, ctx));
}
-FOUND_IT:
-
AutoValidate av(cache);
if (!proc(cache, context)) { // need to reattach
- if (insideMutex) {
- globals.internalAttachCacheToHead(cache);
- } else {
- globals.attachCacheToHead(cache);
- }
+ globals.attachCacheToHead(cache);
cache = NULL;
}
return cache;
@@ -524,9 +518,9 @@ void SkGlyphCache::AttachCache(SkGlyphCache* cache) {
}
void SkGlyphCache::Dump() {
- SkGlyphCache_Globals& globals = getGlobals();
- SkAutoMutexAcquire ac(globals.fMutex);
- SkGlyphCache* cache;
+ SkGlyphCache_Globals& globals = getGlobals();
+ SkScopedLock<SkGlyphCache_Globals::Lock> ac(*globals.fMutex);
+ SkGlyphCache* cache;
globals.validate();
@@ -553,7 +547,7 @@ void SkGlyphCache::Dump() {
///////////////////////////////////////////////////////////////////////////////
void SkGlyphCache_Globals::attachCacheToHead(SkGlyphCache* cache) {
- SkAutoMutexAcquire ac(fMutex);
+ SkScopedLock<Lock> ac(*fMutex);
this->validate();
cache->validate();

Powered by Google App Engine
This is Rietveld 408576698