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

Side by Side Diff: src/core/SkGlyphCache_Globals.h

Issue 1210143004: SkGlyphCache_Globals: SkMutex -> SkSpinlock (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove tls, move autolock and other 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 unified diff | Download patch
« src/core/SkGlyphCache.cpp ('K') | « src/core/SkGlyphCache.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2010 Google Inc. 2 * Copyright 2010 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkGlyphCache_Globals_DEFINED 8 #ifndef SkGlyphCache_Globals_DEFINED
9 #define SkGlyphCache_Globals_DEFINED 9 #define SkGlyphCache_Globals_DEFINED
10 10
11 #include "SkGlyphCache.h" 11 #include "SkGlyphCache.h"
12 #include "SkMutex.h" 12 #include "SkMutex.h"
13 #include "SkSpinlock.h"
13 #include "SkTLS.h" 14 #include "SkTLS.h"
14 15
15 #ifndef SK_DEFAULT_FONT_CACHE_COUNT_LIMIT 16 #ifndef SK_DEFAULT_FONT_CACHE_COUNT_LIMIT
16 #define SK_DEFAULT_FONT_CACHE_COUNT_LIMIT 2048 17 #define SK_DEFAULT_FONT_CACHE_COUNT_LIMIT 2048
17 #endif 18 #endif
18 19
19 #ifndef SK_DEFAULT_FONT_CACHE_LIMIT 20 #ifndef SK_DEFAULT_FONT_CACHE_LIMIT
20 #define SK_DEFAULT_FONT_CACHE_LIMIT (2 * 1024 * 1024) 21 #define SK_DEFAULT_FONT_CACHE_LIMIT (2 * 1024 * 1024)
21 #endif 22 #endif
22 23
23 /////////////////////////////////////////////////////////////////////////////// 24 ///////////////////////////////////////////////////////////////////////////////
24 25
25 class SkMutex; 26 class SkSpinlock;
mtklein_C 2015/07/09 16:46:22 Must be we can remove this now.
herb_g 2015/07/09 18:21:16 Done.
26 27
27 class SkGlyphCache_Globals { 28 class SkGlyphCache_Globals {
28 public: 29 public:
29 enum UseMutex { 30 using Lock = SkSpinlock;
mtklein_C 2015/07/09 16:46:22 now unused?
herb_g 2015/07/09 18:21:16 Removed
30 kNo_UseMutex, // thread-local cache
31 kYes_UseMutex // shared cache
32 };
33 31
34 SkGlyphCache_Globals(UseMutex um) { 32 SkGlyphCache_Globals() {
35 fHead = NULL; 33 fHead = NULL;
36 fTotalMemoryUsed = 0; 34 fTotalMemoryUsed = 0;
37 fCacheSizeLimit = SK_DEFAULT_FONT_CACHE_LIMIT; 35 fCacheSizeLimit = SK_DEFAULT_FONT_CACHE_LIMIT;
38 fCacheCount = 0; 36 fCacheCount = 0;
39 fCacheCountLimit = SK_DEFAULT_FONT_CACHE_COUNT_LIMIT; 37 fCacheCountLimit = SK_DEFAULT_FONT_CACHE_COUNT_LIMIT;
40
41 fMutex = (kYes_UseMutex == um) ? SkNEW(SkMutex) : NULL;
42 } 38 }
43 39
44 ~SkGlyphCache_Globals() { 40 ~SkGlyphCache_Globals() {
45 SkGlyphCache* cache = fHead; 41 SkGlyphCache* cache = fHead;
46 while (cache) { 42 while (cache) {
47 SkGlyphCache* next = cache->fNext; 43 SkGlyphCache* next = cache->fNext;
48 SkDELETE(cache); 44 SkDELETE(cache);
49 cache = next; 45 cache = next;
50 } 46 }
51
52 SkDELETE(fMutex);
53 } 47 }
54 48
55 SkMutex* fMutex; 49 SkSpinlock fLock;
56 50
57 SkGlyphCache* internalGetHead() const { return fHead; } 51 SkGlyphCache* internalGetHead() const { return fHead; }
58 SkGlyphCache* internalGetTail() const; 52 SkGlyphCache* internalGetTail() const;
59 53
60 size_t getTotalMemoryUsed() const { return fTotalMemoryUsed; } 54 size_t getTotalMemoryUsed() const { return fTotalMemoryUsed; }
61 int getCacheCountUsed() const { return fCacheCount; } 55 int getCacheCountUsed() const { return fCacheCount; }
62 56
63 #ifdef SK_DEBUG 57 #ifdef SK_DEBUG
64 void validate() const; 58 void validate() const;
65 #else 59 #else
(...skipping 15 matching lines...) Expand all
81 75
82 void purgeAll(); // does not change budget 76 void purgeAll(); // does not change budget
83 77
84 // call when a glyphcache is available for caching (i.e. not in use) 78 // call when a glyphcache is available for caching (i.e. not in use)
85 void attachCacheToHead(SkGlyphCache*); 79 void attachCacheToHead(SkGlyphCache*);
86 80
87 // can only be called when the mutex is already held 81 // can only be called when the mutex is already held
88 void internalDetachCache(SkGlyphCache*); 82 void internalDetachCache(SkGlyphCache*);
89 void internalAttachCacheToHead(SkGlyphCache*); 83 void internalAttachCacheToHead(SkGlyphCache*);
90 84
91 // can return NULL
92 static SkGlyphCache_Globals* FindTLS() {
93 return (SkGlyphCache_Globals*)SkTLS::Find(CreateTLS);
94 }
95
96 static SkGlyphCache_Globals& GetTLS() {
97 return *(SkGlyphCache_Globals*)SkTLS::Get(CreateTLS, DeleteTLS);
98 }
99
100 static void DeleteTLS() { SkTLS::Delete(CreateTLS); }
101
102 private: 85 private:
103 SkGlyphCache* fHead; 86 SkGlyphCache* fHead;
104 size_t fTotalMemoryUsed; 87 size_t fTotalMemoryUsed;
105 size_t fCacheSizeLimit; 88 size_t fCacheSizeLimit;
106 int32_t fCacheCountLimit; 89 int32_t fCacheCountLimit;
107 int32_t fCacheCount; 90 int32_t fCacheCount;
108 91
109 // Checkout budgets, modulated by the specified min-bytes-needed-to-purge, 92 // Checkout budgets, modulated by the specified min-bytes-needed-to-purge,
110 // and attempt to purge caches to match. 93 // and attempt to purge caches to match.
111 // Returns number of bytes freed. 94 // Returns number of bytes freed.
112 size_t internalPurge(size_t minBytesNeeded = 0); 95 size_t internalPurge(size_t minBytesNeeded = 0);
113
114 static void* CreateTLS() {
115 return SkNEW_ARGS(SkGlyphCache_Globals, (kNo_UseMutex));
116 }
117
118 static void DeleteTLS(void* ptr) {
119 SkDELETE((SkGlyphCache_Globals*)ptr);
120 }
121 }; 96 };
122 97
123 #endif 98 #endif
OLDNEW
« src/core/SkGlyphCache.cpp ('K') | « src/core/SkGlyphCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698