| OLD | NEW |
| 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2015 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/metrics/persistent_memory_allocator.h" | 5 #include "base/metrics/persistent_memory_allocator.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <algorithm> | 8 #include <algorithm> |
| 9 | 9 |
| 10 #include "base/files/memory_mapped_file.h" | 10 #include "base/files/memory_mapped_file.h" |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 volatile BlockHeader queue; // Empty block for linked-list head/tail. | 110 volatile BlockHeader queue; // Empty block for linked-list head/tail. |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 // The "queue" block header is used to detect "last node" so that zero/null | 113 // The "queue" block header is used to detect "last node" so that zero/null |
| 114 // can be used to indicate that it hasn't been added at all. It is part of | 114 // can be used to indicate that it hasn't been added at all. It is part of |
| 115 // the SharedMetadata structure which itself is always located at offset zero. | 115 // the SharedMetadata structure which itself is always located at offset zero. |
| 116 const PersistentMemoryAllocator::Reference | 116 const PersistentMemoryAllocator::Reference |
| 117 PersistentMemoryAllocator::kReferenceQueue = | 117 PersistentMemoryAllocator::kReferenceQueue = |
| 118 offsetof(SharedMetadata, queue); | 118 offsetof(SharedMetadata, queue); |
| 119 | 119 |
| 120 const base::FilePath::CharType PersistentMemoryAllocator::kFileExtension[] = |
| 121 FILE_PATH_LITERAL(".pma"); |
| 122 |
| 123 |
| 120 PersistentMemoryAllocator::Iterator::Iterator( | 124 PersistentMemoryAllocator::Iterator::Iterator( |
| 121 const PersistentMemoryAllocator* allocator) | 125 const PersistentMemoryAllocator* allocator) |
| 122 : allocator_(allocator), last_record_(kReferenceQueue), record_count_(0) {} | 126 : allocator_(allocator), last_record_(kReferenceQueue), record_count_(0) {} |
| 123 | 127 |
| 124 PersistentMemoryAllocator::Iterator::Iterator( | 128 PersistentMemoryAllocator::Iterator::Iterator( |
| 125 const PersistentMemoryAllocator* allocator, | 129 const PersistentMemoryAllocator* allocator, |
| 126 Reference starting_after) | 130 Reference starting_after) |
| 127 : allocator_(allocator), last_record_(starting_after), record_count_(0) { | 131 : allocator_(allocator), last_record_(starting_after), record_count_(0) { |
| 128 // Ensure that the starting point is a valid, iterable block (meaning it can | 132 // Ensure that the starting point is a valid, iterable block (meaning it can |
| 129 // be read and has a non-zero "next" pointer). | 133 // be read and has a non-zero "next" pointer). |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 PersistentMemoryAllocator::Iterator::GetNextOfType(uint32_t type_match) { | 224 PersistentMemoryAllocator::Iterator::GetNextOfType(uint32_t type_match) { |
| 221 Reference ref; | 225 Reference ref; |
| 222 uint32_t type_found; | 226 uint32_t type_found; |
| 223 while ((ref = GetNext(&type_found)) != 0) { | 227 while ((ref = GetNext(&type_found)) != 0) { |
| 224 if (type_found == type_match) | 228 if (type_found == type_match) |
| 225 return ref; | 229 return ref; |
| 226 } | 230 } |
| 227 return kReferenceNull; | 231 return kReferenceNull; |
| 228 } | 232 } |
| 229 | 233 |
| 234 |
| 230 // static | 235 // static |
| 231 bool PersistentMemoryAllocator::IsMemoryAcceptable(const void* base, | 236 bool PersistentMemoryAllocator::IsMemoryAcceptable(const void* base, |
| 232 size_t size, | 237 size_t size, |
| 233 size_t page_size, | 238 size_t page_size, |
| 234 bool readonly) { | 239 bool readonly) { |
| 235 return ((base && reinterpret_cast<uintptr_t>(base) % kAllocAlignment == 0) && | 240 return ((base && reinterpret_cast<uintptr_t>(base) % kAllocAlignment == 0) && |
| 236 (size >= sizeof(SharedMetadata) && size <= kSegmentMaxSize) && | 241 (size >= sizeof(SharedMetadata) && size <= kSegmentMaxSize) && |
| 237 (size >= kSegmentMinSize || readonly) && | 242 (size >= kSegmentMinSize || readonly) && |
| 238 (size % kAllocAlignment == 0 || readonly) && | 243 (size % kAllocAlignment == 0 || readonly) && |
| 239 (page_size == 0 || size % page_size == 0 || readonly)); | 244 (page_size == 0 || size % page_size == 0 || readonly)); |
| (...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 759 | 764 |
| 760 FilePersistentMemoryAllocator::~FilePersistentMemoryAllocator() {} | 765 FilePersistentMemoryAllocator::~FilePersistentMemoryAllocator() {} |
| 761 | 766 |
| 762 // static | 767 // static |
| 763 bool FilePersistentMemoryAllocator::IsFileAcceptable( | 768 bool FilePersistentMemoryAllocator::IsFileAcceptable( |
| 764 const MemoryMappedFile& file) { | 769 const MemoryMappedFile& file) { |
| 765 return IsMemoryAcceptable(file.data(), file.length(), 0, true); | 770 return IsMemoryAcceptable(file.data(), file.length(), 0, true); |
| 766 } | 771 } |
| 767 | 772 |
| 768 } // namespace base | 773 } // namespace base |
| OLD | NEW |