| 1 |
From fcfe5975c9456e808ef893b6c10ff8e09ec9c47f Mon Sep 17 00:00:00 2001 |
| 2 |
From: Kaylee Lubick <[email protected]> |
| 3 |
Date: Thu, 28 May 2026 10:25:19 -0400 |
| 4 |
Subject: [PATCH] Use exclusive mutex in SkFontMgr_android_ndk.cpp |
| 5 |
|
| 6 |
SkLRUCache::find() is mutating so a shared mutex doesn't actually |
| 7 |
buy us anything here. |
| 8 |
|
| 9 |
Change-Id: I9af6986d671c0399f4e3da7c3a6a7a698e95dd13 |
| 10 |
Bug: https://issues.chromium.org/issues/500474409 |
| 11 |
Fixed: 500474409 |
| 12 |
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/1248136 |
| 13 |
Commit-Queue: Alexis Cruz-Ayala <[email protected]> |
| 14 |
Auto-Submit: Kaylee Lubick <[email protected]> |
| 15 |
Reviewed-by: Alexis Cruz-Ayala <[email protected]> |
| 16 |
--- |
| 17 |
src/ports/SkFontMgr_android_ndk.cpp | 12 ++++++------ |
| 18 |
1 file changed, 6 insertions(+), 6 deletions(-) |
| 19 |
|
| 20 |
diff --git a/src/ports/SkFontMgr_android_ndk.cpp b/src/ports/SkFontMgr_android_ndk.cpp |
| 21 |
index 45088cffb1..7a62c40d03 100644 |
| 22 |
--- a/src/ports/SkFontMgr_android_ndk.cpp |
| 23 |
+++ b/src/ports/SkFontMgr_android_ndk.cpp |
| 24 |
@@ -15,9 +15,9 @@ |
| 25 |
#include "include/private/base/SkAssert.h" |
| 26 |
#include "include/private/base/SkFeatures.h" |
| 27 |
#include "include/private/base/SkFloatingPoint.h" |
| 28 |
+#include "include/private/base/SkMutex.h" |
| 29 |
#include "include/private/base/SkTArray.h" |
| 30 |
#include "include/private/base/SkTemplates.h" |
| 31 |
-#include "src/base/SkSharedMutex.h" |
| 32 |
#include "src/base/SkTSort.h" |
| 33 |
#include "src/base/SkUTF.h" |
| 34 |
#include "src/core/SkChecksum.h" |
| 35 |
@@ -722,7 +722,7 @@ public: |
| 36 |
uint32_t fHash; |
| 37 |
}; |
| 38 |
sk_sp<SkTypeface> find(const Request& request) { |
| 39 |
- SkAutoSharedMutexShared lock(fMutex); |
| 40 |
+ SkAutoMutexExclusive lock(fMutex); // SkLRUCache::find() is mutating |
| 41 |
sk_sp<SkTypeface>* typeface = fRequests.find(request); |
| 42 |
if (typeface) { |
| 43 |
return *typeface; |
| 44 |
@@ -730,7 +730,7 @@ public: |
| 45 |
return nullptr; |
| 46 |
} |
| 47 |
void add(const Request& request, sk_sp<SkTypeface> typeface) { |
| 48 |
- SkAutoSharedMutexExclusive lock(fMutex); |
| 49 |
+ SkAutoMutexExclusive lock(fMutex); |
| 50 |
fRequests.insert_or_update(request, std::move(typeface)); |
| 51 |
} |
| 52 |
|
| 53 |
@@ -773,7 +773,7 @@ public: |
| 54 |
uint32_t fHash; |
| 55 |
}; |
| 56 |
sk_sp<SkTypeface> find(const Match& match) { |
| 57 |
- SkAutoSharedMutexShared lock(fMutex); |
| 58 |
+ SkAutoMutexExclusive lock(fMutex); |
| 59 |
sk_sp<SkTypeface>* typeface = fMatches.find(match); |
| 60 |
if (typeface) { |
| 61 |
return *typeface; |
| 62 |
@@ -781,13 +781,13 @@ public: |
| 63 |
return nullptr; |
| 64 |
} |
| 65 |
void add(Match&& match, sk_sp<SkTypeface> typeface) { |
| 66 |
- SkAutoSharedMutexExclusive lock(fMutex); |
| 67 |
+ SkAutoMutexExclusive lock(fMutex); |
| 68 |
fMatches.insert_or_update(std::move(match), typeface); |
| 69 |
} |
| 70 |
private: |
| 71 |
SkLRUCache<Request, sk_sp<SkTypeface>, Request::Hash> fRequests; |
| 72 |
SkLRUCache<Match, sk_sp<SkTypeface>, Match::Hash> fMatches; |
| 73 |
- SkSharedMutex fMutex; |
| 74 |
+ SkMutex fMutex; |
| 75 |
}; |
| 76 |
|
| 77 |
sk_sp<SkTypeface> adjustForStyle(sk_sp<SkTypeface_AndroidNDK>&& typeface, SkFontStyle style, |
| 78 |
-- |
| 79 |
2.53.0 |
| 80 |
|