reduce mutex use and switch to spinlock

* Combine find and makeMRU.
* Switch from SkMutex to SkSpinLock

In the gm 'paragraph_$' this reduces acquiring the lock from 1.2% to 0.7%
as measured by instruments and nanobench.

Change-Id: I33e3af31825f175c9de42f001acf68ffe3623a8a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/305564
Reviewed-by: Ben Wagner <bungeman@google.com>
Commit-Queue: Herb Derby <herb@google.com>
diff --git a/src/gpu/text/GrTextBlobCache.cpp b/src/gpu/text/GrTextBlobCache.cpp
index 988ef81..a7647be 100644
--- a/src/gpu/text/GrTextBlobCache.cpp
+++ b/src/gpu/text/GrTextBlobCache.cpp
@@ -26,20 +26,30 @@
                                 const SkMatrix& viewMatrix) {
     sk_sp<GrTextBlob> cacheBlob(GrTextBlob::Make(glyphRunList, viewMatrix));
     cacheBlob->setupKey(key, blurRec, glyphRunList.paint());
-    SkAutoMutexExclusive lock{fMutex};
+    SkAutoSpinlock lock{fSpinLock};
     this->internalAdd(cacheBlob);
     glyphRunList.temporaryShuntBlobNotifyAddedToCache(fMessageBusID);
     return cacheBlob;
 }
 
-sk_sp<GrTextBlob> GrTextBlobCache::find(const GrTextBlob::Key& key) const {
-    SkAutoMutexExclusive lock{fMutex};
-    const auto* idEntry = fBlobIDCache.find(key.fUniqueID);
-    return idEntry ? idEntry->find(key) : nullptr;
+sk_sp<GrTextBlob> GrTextBlobCache::find(const GrTextBlob::Key& key) {
+    SkAutoSpinlock lock{fSpinLock};
+    const BlobIDCacheEntry* idEntry = fBlobIDCache.find(key.fUniqueID);
+    if (idEntry == nullptr) {
+        return nullptr;
+    }
+
+    sk_sp<GrTextBlob> blob = idEntry->find(key);
+    GrTextBlob* blobPtr = blob.get();
+    if (blobPtr != nullptr && blobPtr != fBlobList.head()) {
+        fBlobList.remove(blobPtr);
+        fBlobList.addToHead(blobPtr);
+    }
+    return blob;
 }
 
 void GrTextBlobCache::remove(GrTextBlob* blob) {
-    SkAutoMutexExclusive lock{fMutex};
+    SkAutoSpinlock lock{fSpinLock};
     this->internalRemove(blob);
 }
 
@@ -56,18 +66,8 @@
     }
 }
 
-void GrTextBlobCache::makeMRU(GrTextBlob* blob) {
-    SkAutoMutexExclusive lock{fMutex};
-    if (fBlobList.head() == blob) {
-        return;
-    }
-
-    fBlobList.remove(blob);
-    fBlobList.addToHead(blob);
-}
-
 void GrTextBlobCache::freeAll() {
-    SkAutoMutexExclusive lock{fMutex};
+    SkAutoSpinlock lock{fSpinLock};
     fBlobIDCache.reset();
     fBlobList.reset();
     fCurrentSize = 0;
@@ -79,7 +79,7 @@
 }
 
 void GrTextBlobCache::purgeStaleBlobs() {
-    SkAutoMutexExclusive lock{fMutex};
+    SkAutoSpinlock lock{fSpinLock};
     this->internalPurgeStaleBlobs();
 }
 
@@ -106,12 +106,12 @@
 }
 
 size_t GrTextBlobCache::usedBytes() const {
-    SkAutoMutexExclusive lock{fMutex};
+    SkAutoSpinlock lock{fSpinLock};
     return fCurrentSize;
 }
 
 bool GrTextBlobCache::isOverBudget() const {
-    SkAutoMutexExclusive lock{fMutex};
+    SkAutoSpinlock lock{fSpinLock};
     return fCurrentSize > fSizeBudget;
 }