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

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: address more comments 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
« no previous file with comments | « 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
27 class SkGlyphCache_Globals { 26 class SkGlyphCache_Globals {
28 public: 27 public:
29 enum UseMutex { 28 SkGlyphCache_Globals() {
30 kNo_UseMutex, // thread-local cache
31 kYes_UseMutex // shared cache
32 };
33
34 SkGlyphCache_Globals(UseMutex um) {
35 fHead = NULL; 29 fHead = NULL;
36 fTotalMemoryUsed = 0; 30 fTotalMemoryUsed = 0;
37 fCacheSizeLimit = SK_DEFAULT_FONT_CACHE_LIMIT; 31 fCacheSizeLimit = SK_DEFAULT_FONT_CACHE_LIMIT;
38 fCacheCount = 0; 32 fCacheCount = 0;
39 fCacheCountLimit = SK_DEFAULT_FONT_CACHE_COUNT_LIMIT; 33 fCacheCountLimit = SK_DEFAULT_FONT_CACHE_COUNT_LIMIT;
40
41 fMutex = (kYes_UseMutex == um) ? SkNEW(SkMutex) : NULL;
42 } 34 }
43 35
44 ~SkGlyphCache_Globals() { 36 ~SkGlyphCache_Globals() {
45 SkGlyphCache* cache = fHead; 37 SkGlyphCache* cache = fHead;
46 while (cache) { 38 while (cache) {
47 SkGlyphCache* next = cache->fNext; 39 SkGlyphCache* next = cache->fNext;
48 SkDELETE(cache); 40 SkDELETE(cache);
49 cache = next; 41 cache = next;
50 } 42 }
51
52 SkDELETE(fMutex);
53 } 43 }
54 44
55 SkMutex* fMutex; 45 SkSpinlock fLock;
56 46
57 SkGlyphCache* internalGetHead() const { return fHead; } 47 SkGlyphCache* internalGetHead() const { return fHead; }
58 SkGlyphCache* internalGetTail() const; 48 SkGlyphCache* internalGetTail() const;
59 49
60 size_t getTotalMemoryUsed() const { return fTotalMemoryUsed; } 50 size_t getTotalMemoryUsed() const { return fTotalMemoryUsed; }
61 int getCacheCountUsed() const { return fCacheCount; } 51 int getCacheCountUsed() const { return fCacheCount; }
62 52
63 #ifdef SK_DEBUG 53 #ifdef SK_DEBUG
64 void validate() const; 54 void validate() const;
65 #else 55 #else
(...skipping 15 matching lines...) Expand all
81 71
82 void purgeAll(); // does not change budget 72 void purgeAll(); // does not change budget
83 73
84 // call when a glyphcache is available for caching (i.e. not in use) 74 // call when a glyphcache is available for caching (i.e. not in use)
85 void attachCacheToHead(SkGlyphCache*); 75 void attachCacheToHead(SkGlyphCache*);
86 76
87 // can only be called when the mutex is already held 77 // can only be called when the mutex is already held
88 void internalDetachCache(SkGlyphCache*); 78 void internalDetachCache(SkGlyphCache*);
89 void internalAttachCacheToHead(SkGlyphCache*); 79 void internalAttachCacheToHead(SkGlyphCache*);
90 80
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: 81 private:
103 SkGlyphCache* fHead; 82 SkGlyphCache* fHead;
104 size_t fTotalMemoryUsed; 83 size_t fTotalMemoryUsed;
105 size_t fCacheSizeLimit; 84 size_t fCacheSizeLimit;
106 int32_t fCacheCountLimit; 85 int32_t fCacheCountLimit;
107 int32_t fCacheCount; 86 int32_t fCacheCount;
108 87
109 // Checkout budgets, modulated by the specified min-bytes-needed-to-purge, 88 // Checkout budgets, modulated by the specified min-bytes-needed-to-purge,
110 // and attempt to purge caches to match. 89 // and attempt to purge caches to match.
111 // Returns number of bytes freed. 90 // Returns number of bytes freed.
112 size_t internalPurge(size_t minBytesNeeded = 0); 91 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 }; 92 };
122 93
123 #endif 94 #endif
OLDNEW
« no previous file with comments | « src/core/SkGlyphCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698