OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/memory/discardable_memory_manager.h" | 5 #include "base/memory/discardable_memory_manager.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/containers/hash_tables.h" | 8 #include "base/containers/hash_tables.h" |
9 #include "base/containers/mru_cache.h" | 9 #include "base/containers/mru_cache.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
77 AutoLock lock(lock_); | 77 AutoLock lock(lock_); |
78 AllocationMap::iterator it = allocations_.Peek(allocation); | 78 AllocationMap::iterator it = allocations_.Peek(allocation); |
79 DCHECK(it != allocations_.end()); | 79 DCHECK(it != allocations_.end()); |
80 const AllocationInfo& info = it->second; | 80 const AllocationInfo& info = it->second; |
81 | 81 |
82 if (info.purgable) { | 82 if (info.purgable) { |
83 size_t bytes_purgable = info.bytes; | 83 size_t bytes_purgable = info.bytes; |
84 DCHECK_LE(bytes_purgable, bytes_allocated_); | 84 DCHECK_LE(bytes_purgable, bytes_allocated_); |
85 bytes_allocated_ -= bytes_purgable; | 85 bytes_allocated_ -= bytes_purgable; |
86 BytesAllocatedChanged(); | 86 BytesAllocatedChanged(); |
87 } else { | |
88 // Note that Purge() which is called below requires the Allocation instance | |
89 // to be unlocked. | |
90 allocation->ReleaseLock(); | |
reveman
2014/04/26 00:13:37
It's currently up to the client to call Discardabl
| |
87 } | 91 } |
92 | |
93 // Purge the allocation here while the mutex is acquired to let the underlying | |
94 // Allocation instance not have to deal with synchronization on its own. | |
95 allocation->Purge(); | |
reveman
2014/04/26 00:13:37
I don't think we should do this here. I prefer to
| |
96 | |
88 allocations_.Erase(it); | 97 allocations_.Erase(it); |
89 } | 98 } |
90 | 99 |
91 bool DiscardableMemoryManager::AcquireLock(Allocation* allocation, | 100 bool DiscardableMemoryManager::AcquireLock(Allocation* allocation, |
92 bool* purged) { | 101 bool* purged) { |
93 AutoLock lock(lock_); | 102 AutoLock lock(lock_); |
94 // Note: |allocations_| is an MRU cache, and use of |Get| here updates that | 103 // Note: |allocations_| is an MRU cache, and use of |Get| here updates that |
95 // cache. | 104 // cache. |
96 AllocationMap::iterator it = allocations_.Get(allocation); | 105 AllocationMap::iterator it = allocations_.Get(allocation); |
97 DCHECK(it != allocations_.end()); | 106 DCHECK(it != allocations_.end()); |
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 void DiscardableMemoryManager::EnforcePolicyWithLockAcquired() { | 226 void DiscardableMemoryManager::EnforcePolicyWithLockAcquired() { |
218 PurgeLRUWithLockAcquiredUntilUsageIsWithin(memory_limit_); | 227 PurgeLRUWithLockAcquiredUntilUsageIsWithin(memory_limit_); |
219 } | 228 } |
220 | 229 |
221 void DiscardableMemoryManager::BytesAllocatedChanged() const { | 230 void DiscardableMemoryManager::BytesAllocatedChanged() const { |
222 TRACE_COUNTER_ID1("base", "DiscardableMemoryUsage", this, bytes_allocated_); | 231 TRACE_COUNTER_ID1("base", "DiscardableMemoryUsage", this, bytes_allocated_); |
223 } | 232 } |
224 | 233 |
225 } // namespace internal | 234 } // namespace internal |
226 } // namespace base | 235 } // namespace base |
OLD | NEW |