From fcfe5975c9456e808ef893b6c10ff8e09ec9c47f Mon Sep 17 00:00:00 2001
From: Kaylee Lubick <kjlubick@google.com>
Date: Thu, 28 May 2026 10:25:19 -0400
Subject: [PATCH] Use exclusive mutex in SkFontMgr_android_ndk.cpp

SkLRUCache::find() is mutating so a shared mutex doesn't actually
buy us anything here.

Change-Id: I9af6986d671c0399f4e3da7c3a6a7a698e95dd13
Bug: https://issues.chromium.org/issues/500474409
Fixed: 500474409
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1248136
Commit-Queue: Alexis Cruz-Ayala <alexisdavidc@google.com>
Auto-Submit: Kaylee Lubick <kjlubick@google.com>
Reviewed-by: Alexis Cruz-Ayala <alexisdavidc@google.com>
---
 src/ports/SkFontMgr_android_ndk.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/ports/SkFontMgr_android_ndk.cpp b/src/ports/SkFontMgr_android_ndk.cpp
index 45088cffb1..7a62c40d03 100644
--- a/src/ports/SkFontMgr_android_ndk.cpp
+++ b/src/ports/SkFontMgr_android_ndk.cpp
@@ -15,9 +15,9 @@
 #include "include/private/base/SkAssert.h"
 #include "include/private/base/SkFeatures.h"
 #include "include/private/base/SkFloatingPoint.h"
+#include "include/private/base/SkMutex.h"
 #include "include/private/base/SkTArray.h"
 #include "include/private/base/SkTemplates.h"
-#include "src/base/SkSharedMutex.h"
 #include "src/base/SkTSort.h"
 #include "src/base/SkUTF.h"
 #include "src/core/SkChecksum.h"
@@ -722,7 +722,7 @@ public:
         uint32_t fHash;
     };
     sk_sp<SkTypeface> find(const Request& request) {
-        SkAutoSharedMutexShared lock(fMutex);
+        SkAutoMutexExclusive lock(fMutex);  // SkLRUCache::find() is mutating
         sk_sp<SkTypeface>* typeface = fRequests.find(request);
         if (typeface) {
             return *typeface;
@@ -730,7 +730,7 @@ public:
         return nullptr;
     }
     void add(const Request& request, sk_sp<SkTypeface> typeface) {
-        SkAutoSharedMutexExclusive lock(fMutex);
+        SkAutoMutexExclusive lock(fMutex);
         fRequests.insert_or_update(request, std::move(typeface));
     }
 
@@ -773,7 +773,7 @@ public:
         uint32_t fHash;
     };
     sk_sp<SkTypeface> find(const Match& match) {
-        SkAutoSharedMutexShared lock(fMutex);
+        SkAutoMutexExclusive lock(fMutex);
         sk_sp<SkTypeface>* typeface = fMatches.find(match);
         if (typeface) {
             return *typeface;
@@ -781,13 +781,13 @@ public:
         return nullptr;
     }
     void add(Match&& match, sk_sp<SkTypeface> typeface) {
-        SkAutoSharedMutexExclusive lock(fMutex);
+        SkAutoMutexExclusive lock(fMutex);
         fMatches.insert_or_update(std::move(match), typeface);
     }
 private:
     SkLRUCache<Request, sk_sp<SkTypeface>, Request::Hash> fRequests;
     SkLRUCache<Match, sk_sp<SkTypeface>, Match::Hash> fMatches;
-    SkSharedMutex fMutex;
+    SkMutex fMutex;
 };
 
 sk_sp<SkTypeface> adjustForStyle(sk_sp<SkTypeface_AndroidNDK>&& typeface, SkFontStyle style,
-- 
2.53.0

