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 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_ | 5 #ifndef BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_ |
6 #define BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_ | 6 #define BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 // ashmem regions and is expected to be greater or equal than 32 MBytes. | 37 // ashmem regions and is expected to be greater or equal than 32 MBytes. |
38 DiscardableMemoryAllocator(const std::string& name, | 38 DiscardableMemoryAllocator(const std::string& name, |
39 size_t ashmem_region_size); | 39 size_t ashmem_region_size); |
40 | 40 |
41 ~DiscardableMemoryAllocator(); | 41 ~DiscardableMemoryAllocator(); |
42 | 42 |
43 // Note that the allocator must outlive the returned DiscardableMemory | 43 // Note that the allocator must outlive the returned DiscardableMemory |
44 // instance. | 44 // instance. |
45 scoped_ptr<DiscardableMemory> Allocate(size_t size); | 45 scoped_ptr<DiscardableMemory> Allocate(size_t size); |
46 | 46 |
| 47 // Returns the size of the last ashmem region which was created. This is used |
| 48 // for testing only. |
| 49 size_t last_ashmem_region_size() const; |
| 50 |
47 private: | 51 private: |
48 class AshmemRegion; | 52 class AshmemRegion; |
49 class DiscardableAshmemChunk; | 53 class DiscardableAshmemChunk; |
50 | 54 |
51 void DeleteAshmemRegion_Locked(AshmemRegion* region); | 55 void DeleteAshmemRegion_Locked(AshmemRegion* region); |
52 | 56 |
53 base::ThreadChecker thread_checker_; | 57 ThreadChecker thread_checker_; |
54 const std::string name_; | 58 const std::string name_; |
55 const size_t ashmem_region_size_; | 59 const size_t ashmem_region_size_; |
56 base::Lock lock_; | 60 mutable Lock lock_; |
| 61 size_t last_ashmem_region_size_; |
57 ScopedVector<AshmemRegion> ashmem_regions_; | 62 ScopedVector<AshmemRegion> ashmem_regions_; |
58 | 63 |
59 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryAllocator); | 64 DISALLOW_COPY_AND_ASSIGN(DiscardableMemoryAllocator); |
60 }; | 65 }; |
61 | 66 |
62 } // namespace internal | 67 } // namespace internal |
63 } // namespace base | 68 } // namespace base |
64 | 69 |
65 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_ | 70 #endif // BASE_MEMORY_DISCARDABLE_MEMORY_ALLOCATOR_H_ |
OLD | NEW |