OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 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 #include "SkDiscardableMemory.h" | 8 #include "SkDiscardableMemory.h" |
9 #include "SkDiscardableMemoryPool.h" | 9 #include "SkDiscardableMemoryPool.h" |
10 #include "SkLazyPtr.h" | 10 #include "SkLazyPtr.h" |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
138 #endif // SK_LAZY_CACHE_STATS | 138 #endif // SK_LAZY_CACHE_STATS |
139 } | 139 } |
140 DiscardableMemoryPool::~DiscardableMemoryPool() { | 140 DiscardableMemoryPool::~DiscardableMemoryPool() { |
141 // PoolDiscardableMemory objects that belong to this pool are | 141 // PoolDiscardableMemory objects that belong to this pool are |
142 // always deleted before deleting this pool since each one has a | 142 // always deleted before deleting this pool since each one has a |
143 // ref to the pool. | 143 // ref to the pool. |
144 SkASSERT(fList.isEmpty()); | 144 SkASSERT(fList.isEmpty()); |
145 } | 145 } |
146 | 146 |
147 void DiscardableMemoryPool::dumpDownTo(size_t budget) { | 147 void DiscardableMemoryPool::dumpDownTo(size_t budget) { |
148 // assert((NULL = fMutex) || fMutex->isLocked()); | 148 #ifdef SK_DEBUG |
mtklein
2014/06/11 15:59:04
Doesn't really need the SK_DEBUG check?
hal.canary
2014/06/11 16:17:32
Yes, because in release, you could call NULL->asse
| |
149 // TODO(halcanary) implement bool fMutex::isLocked(). | 149 if (fMutex != NULL) { |
150 // WARNING: only call this function after aquiring lock. | 150 fMutex->assertHeld(); |
151 } | |
152 #endif // SK_DEBUG | |
151 if (fUsed <= budget) { | 153 if (fUsed <= budget) { |
152 return; | 154 return; |
153 } | 155 } |
154 typedef SkTInternalLList<PoolDiscardableMemory>::Iter Iter; | 156 typedef SkTInternalLList<PoolDiscardableMemory>::Iter Iter; |
155 Iter iter; | 157 Iter iter; |
156 PoolDiscardableMemory* cur = iter.init(fList, Iter::kTail_IterStart); | 158 PoolDiscardableMemory* cur = iter.init(fList, Iter::kTail_IterStart); |
157 while ((fUsed > budget) && (NULL != cur)) { | 159 while ((fUsed > budget) && (NULL != cur)) { |
158 if (!cur->fLocked) { | 160 if (!cur->fLocked) { |
159 PoolDiscardableMemory* dm = cur; | 161 PoolDiscardableMemory* dm = cur; |
160 SkASSERT(dm->fPointer != NULL); | 162 SkASSERT(dm->fPointer != NULL); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
262 SkDiscardableMemoryPool* SkGetGlobalDiscardableMemoryPool() { | 264 SkDiscardableMemoryPool* SkGetGlobalDiscardableMemoryPool() { |
263 SK_DECLARE_STATIC_LAZY_PTR(SkDiscardableMemoryPool, global, create_global_po ol); | 265 SK_DECLARE_STATIC_LAZY_PTR(SkDiscardableMemoryPool, global, create_global_po ol); |
264 return global.get(); | 266 return global.get(); |
265 } | 267 } |
266 | 268 |
267 // defined in SkImageGenerator.h | 269 // defined in SkImageGenerator.h |
268 void SkPurgeGlobalDiscardableMemoryPool() { | 270 void SkPurgeGlobalDiscardableMemoryPool() { |
269 SkGetGlobalDiscardableMemoryPool()->dumpPool(); | 271 SkGetGlobalDiscardableMemoryPool()->dumpPool(); |
270 } | 272 } |
271 //////////////////////////////////////////////////////////////////////////////// | 273 //////////////////////////////////////////////////////////////////////////////// |
OLD | NEW |