| 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 "content/common/discardable_shared_memory_heap.h" | 5 #include "content/common/discardable_shared_memory_heap.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/memory/discardable_shared_memory.h" | 10 #include "base/memory/discardable_shared_memory.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 InsertIntoFreeList(span.Pass()); | 169 InsertIntoFreeList(span.Pass()); |
| 170 } | 170 } |
| 171 | 171 |
| 172 scoped_ptr<DiscardableSharedMemoryHeap::Span> | 172 scoped_ptr<DiscardableSharedMemoryHeap::Span> |
| 173 DiscardableSharedMemoryHeap::Split(Span* span, size_t blocks) { | 173 DiscardableSharedMemoryHeap::Split(Span* span, size_t blocks) { |
| 174 DCHECK(blocks); | 174 DCHECK(blocks); |
| 175 DCHECK_LT(blocks, span->length_); | 175 DCHECK_LT(blocks, span->length_); |
| 176 | 176 |
| 177 scoped_ptr<Span> leftover(new Span( | 177 scoped_ptr<Span> leftover(new Span( |
| 178 span->shared_memory_, span->start_ + blocks, span->length_ - blocks)); | 178 span->shared_memory_, span->start_ + blocks, span->length_ - blocks)); |
| 179 DCHECK(leftover->length_ == 1 || | 179 DCHECK_IMPLIES(leftover->length_ > 1, |
| 180 spans_.find(leftover->start_) == spans_.end()); | 180 spans_.find(leftover->start_) == spans_.end()); |
| 181 RegisterSpan(leftover.get()); | 181 RegisterSpan(leftover.get()); |
| 182 spans_[span->start_ + blocks - 1] = span; | 182 spans_[span->start_ + blocks - 1] = span; |
| 183 span->length_ = blocks; | 183 span->length_ = blocks; |
| 184 return leftover.Pass(); | 184 return leftover.Pass(); |
| 185 } | 185 } |
| 186 | 186 |
| 187 scoped_ptr<DiscardableSharedMemoryHeap::Span> | 187 scoped_ptr<DiscardableSharedMemoryHeap::Span> |
| 188 DiscardableSharedMemoryHeap::SearchFreeLists(size_t blocks, size_t slack) { | 188 DiscardableSharedMemoryHeap::SearchFreeLists(size_t blocks, size_t slack) { |
| 189 DCHECK(blocks); | 189 DCHECK(blocks); |
| 190 | 190 |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 | 274 |
| 275 scoped_ptr<DiscardableSharedMemoryHeap::Span> | 275 scoped_ptr<DiscardableSharedMemoryHeap::Span> |
| 276 DiscardableSharedMemoryHeap::Carve(Span* span, size_t blocks) { | 276 DiscardableSharedMemoryHeap::Carve(Span* span, size_t blocks) { |
| 277 scoped_ptr<Span> serving = RemoveFromFreeList(span); | 277 scoped_ptr<Span> serving = RemoveFromFreeList(span); |
| 278 | 278 |
| 279 const int extra = serving->length_ - blocks; | 279 const int extra = serving->length_ - blocks; |
| 280 if (extra) { | 280 if (extra) { |
| 281 scoped_ptr<Span> leftover( | 281 scoped_ptr<Span> leftover( |
| 282 new Span(serving->shared_memory_, serving->start_ + blocks, extra)); | 282 new Span(serving->shared_memory_, serving->start_ + blocks, extra)); |
| 283 leftover->set_is_locked(false); | 283 leftover->set_is_locked(false); |
| 284 DCHECK(extra == 1 || spans_.find(leftover->start_) == spans_.end()); | 284 DCHECK_IMPLIES(extra > 1, spans_.find(leftover->start_) == spans_.end()); |
| 285 RegisterSpan(leftover.get()); | 285 RegisterSpan(leftover.get()); |
| 286 | 286 |
| 287 // No need to coalesce as the previous span of |leftover| was just split | 287 // No need to coalesce as the previous span of |leftover| was just split |
| 288 // and the next span of |leftover| was not previously coalesced with | 288 // and the next span of |leftover| was not previously coalesced with |
| 289 // |span|. | 289 // |span|. |
| 290 InsertIntoFreeList(leftover.Pass()); | 290 InsertIntoFreeList(leftover.Pass()); |
| 291 | 291 |
| 292 serving->length_ = blocks; | 292 serving->length_ = blocks; |
| 293 spans_[serving->start_ + blocks - 1] = serving.get(); | 293 spans_[serving->start_ + blocks - 1] = serving.get(); |
| 294 } | 294 } |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 449 ScopedVector<ScopedMemorySegment>::const_iterator it = | 449 ScopedVector<ScopedMemorySegment>::const_iterator it = |
| 450 std::find_if(memory_segments_.begin(), memory_segments_.end(), | 450 std::find_if(memory_segments_.begin(), memory_segments_.end(), |
| 451 [span](const ScopedMemorySegment* segment) { | 451 [span](const ScopedMemorySegment* segment) { |
| 452 return segment->ContainsSpan(span); | 452 return segment->ContainsSpan(span); |
| 453 }); | 453 }); |
| 454 DCHECK(it != memory_segments_.end()); | 454 DCHECK(it != memory_segments_.end()); |
| 455 return (*it)->CreateMemoryAllocatorDump(span, block_size_, name, pmd); | 455 return (*it)->CreateMemoryAllocatorDump(span, block_size_, name, pmd); |
| 456 } | 456 } |
| 457 | 457 |
| 458 } // namespace content | 458 } // namespace content |
| OLD | NEW |