| 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 if (fMutex != NULL) { |
| 149 // TODO(halcanary) implement bool fMutex::isLocked(). | 149 fMutex->assertHeld(); |
| 150 // WARNING: only call this function after aquiring lock. | 150 } |
| 151 if (fUsed <= budget) { | 151 if (fUsed <= budget) { |
| 152 return; | 152 return; |
| 153 } | 153 } |
| 154 typedef SkTInternalLList<PoolDiscardableMemory>::Iter Iter; | 154 typedef SkTInternalLList<PoolDiscardableMemory>::Iter Iter; |
| 155 Iter iter; | 155 Iter iter; |
| 156 PoolDiscardableMemory* cur = iter.init(fList, Iter::kTail_IterStart); | 156 PoolDiscardableMemory* cur = iter.init(fList, Iter::kTail_IterStart); |
| 157 while ((fUsed > budget) && (NULL != cur)) { | 157 while ((fUsed > budget) && (NULL != cur)) { |
| 158 if (!cur->fLocked) { | 158 if (!cur->fLocked) { |
| 159 PoolDiscardableMemory* dm = cur; | 159 PoolDiscardableMemory* dm = cur; |
| 160 SkASSERT(dm->fPointer != NULL); | 160 SkASSERT(dm->fPointer != NULL); |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 SkDiscardableMemoryPool* SkGetGlobalDiscardableMemoryPool() { | 262 SkDiscardableMemoryPool* SkGetGlobalDiscardableMemoryPool() { |
| 263 SK_DECLARE_STATIC_LAZY_PTR(SkDiscardableMemoryPool, global, create_global_po
ol); | 263 SK_DECLARE_STATIC_LAZY_PTR(SkDiscardableMemoryPool, global, create_global_po
ol); |
| 264 return global.get(); | 264 return global.get(); |
| 265 } | 265 } |
| 266 | 266 |
| 267 // defined in SkImageGenerator.h | 267 // defined in SkImageGenerator.h |
| 268 void SkPurgeGlobalDiscardableMemoryPool() { | 268 void SkPurgeGlobalDiscardableMemoryPool() { |
| 269 SkGetGlobalDiscardableMemoryPool()->dumpPool(); | 269 SkGetGlobalDiscardableMemoryPool()->dumpPool(); |
| 270 } | 270 } |
| 271 //////////////////////////////////////////////////////////////////////////////// | 271 //////////////////////////////////////////////////////////////////////////////// |
| OLD | NEW |