| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_allocator_android.h" | 5 #include "base/memory/discardable_memory_allocator_android.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <cmath> | 8 #include <cmath> |
| 9 #include <set> | 9 #include <set> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 117 const std::string& name, | 117 const std::string& name, |
| 118 DiscardableMemoryAllocator* allocator) { | 118 DiscardableMemoryAllocator* allocator) { |
| 119 DCHECK_EQ(size, AlignToNextPage(size)); | 119 DCHECK_EQ(size, AlignToNextPage(size)); |
| 120 int fd; | 120 int fd; |
| 121 void* base; | 121 void* base; |
| 122 if (!internal::CreateAshmemRegion(name.c_str(), size, &fd, &base)) | 122 if (!internal::CreateAshmemRegion(name.c_str(), size, &fd, &base)) |
| 123 return scoped_ptr<AshmemRegion>(); | 123 return scoped_ptr<AshmemRegion>(); |
| 124 return make_scoped_ptr(new AshmemRegion(fd, size, base, allocator)); | 124 return make_scoped_ptr(new AshmemRegion(fd, size, base, allocator)); |
| 125 } | 125 } |
| 126 | 126 |
| 127 virtual ~AshmemRegion() { | 127 ~AshmemRegion() { |
| 128 const bool result = internal::CloseAshmemRegion(fd_, size_, base_); | 128 const bool result = internal::CloseAshmemRegion(fd_, size_, base_); |
| 129 DCHECK(result); | 129 DCHECK(result); |
| 130 } | 130 } |
| 131 | 131 |
| 132 // Returns a new instance of DiscardableMemory whose size is greater or equal | 132 // Returns a new instance of DiscardableMemory whose size is greater or equal |
| 133 // than |actual_size| (which is expected to be greater or equal than | 133 // than |actual_size| (which is expected to be greater or equal than |
| 134 // |client_requested_size|). | 134 // |client_requested_size|). |
| 135 // Allocation works as follows: | 135 // Allocation works as follows: |
| 136 // 1) Reuse a previously freed chunk and return it if it succeeded. See | 136 // 1) Reuse a previously freed chunk and return it if it succeeded. See |
| 137 // ReuseFreeChunk_Locked() below for more information. | 137 // ReuseFreeChunk_Locked() below for more information. |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 DCHECK_LE(ashmem_regions_.size(), 5U); | 442 DCHECK_LE(ashmem_regions_.size(), 5U); |
| 443 const ScopedVector<AshmemRegion>::iterator it = std::find( | 443 const ScopedVector<AshmemRegion>::iterator it = std::find( |
| 444 ashmem_regions_.begin(), ashmem_regions_.end(), region); | 444 ashmem_regions_.begin(), ashmem_regions_.end(), region); |
| 445 DCHECK_NE(ashmem_regions_.end(), it); | 445 DCHECK_NE(ashmem_regions_.end(), it); |
| 446 std::swap(*it, ashmem_regions_.back()); | 446 std::swap(*it, ashmem_regions_.back()); |
| 447 ashmem_regions_.pop_back(); | 447 ashmem_regions_.pop_back(); |
| 448 } | 448 } |
| 449 | 449 |
| 450 } // namespace internal | 450 } // namespace internal |
| 451 } // namespace base | 451 } // namespace base |
| OLD | NEW |