| 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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 std::atomic<uint32_t> next; // Pointer to the next block when iterating. | 83 std::atomic<uint32_t> next; // Pointer to the next block when iterating. |
| 84 }; | 84 }; |
| 85 | 85 |
| 86 // The shared metadata exists once at the top of the memory segment to | 86 // The shared metadata exists once at the top of the memory segment to |
| 87 // describe the state of the allocator to all processes. | 87 // describe the state of the allocator to all processes. |
| 88 struct PersistentMemoryAllocator::SharedMetadata { | 88 struct PersistentMemoryAllocator::SharedMetadata { |
| 89 uint32_t cookie; // Some value that indicates complete initialization. | 89 uint32_t cookie; // Some value that indicates complete initialization. |
| 90 uint32_t size; // Total size of memory segment. | 90 uint32_t size; // Total size of memory segment. |
| 91 uint32_t page_size; // Paging size within memory segment. | 91 uint32_t page_size; // Paging size within memory segment. |
| 92 uint32_t version; // Version code so upgrades don't break. | 92 uint32_t version; // Version code so upgrades don't break. |
| 93 std::atomic<uint32_t> freeptr; // Offset/ref to first free space in segment. | |
| 94 std::atomic<uint32_t> flags; // Bitfield of information flags. | |
| 95 uint64_t id; // Arbitrary ID number given by creator. | 93 uint64_t id; // Arbitrary ID number given by creator. |
| 96 uint32_t name; // Reference to stored name string. | 94 uint32_t name; // Reference to stored name string. |
| 97 | 95 |
| 96 // Above is read-only after first construction. Below may be changed and |
| 97 // so must be marked "volatile" to provide correct inter-process behavior. |
| 98 |
| 99 // Bitfield of information flags. Access to this should be done through |
| 100 // the CheckFlag() and SetFlag() methods defined above. |
| 101 volatile std::atomic<uint32_t> flags; |
| 102 |
| 103 // Offset/reference to first free space in segment. |
| 104 volatile std::atomic<uint32_t> freeptr; |
| 105 |
| 98 // The "iterable" queue is an M&S Queue as described here, append-only: | 106 // The "iterable" queue is an M&S Queue as described here, append-only: |
| 99 // https://www.research.ibm.com/people/m/michael/podc-1996.pdf | 107 // https://www.research.ibm.com/people/m/michael/podc-1996.pdf |
| 100 std::atomic<uint32_t> tailptr; // Last block available for iteration. | 108 volatile std::atomic<uint32_t> tailptr; // Last block of iteration queue. |
| 101 BlockHeader queue; // Empty block for linked-list head/tail. (must be last) | 109 volatile BlockHeader queue; // Empty block for linked-list head/tail. |
| 102 }; | 110 }; |
| 103 | 111 |
| 104 // The "queue" block header is used to detect "last node" so that zero/null | 112 // The "queue" block header is used to detect "last node" so that zero/null |
| 105 // can be used to indicate that it hasn't been added at all. It is part of | 113 // can be used to indicate that it hasn't been added at all. It is part of |
| 106 // the SharedMetadata structure which itself is always located at offset zero. | 114 // the SharedMetadata structure which itself is always located at offset zero. |
| 107 const PersistentMemoryAllocator::Reference | 115 const PersistentMemoryAllocator::Reference |
| 108 PersistentMemoryAllocator::kReferenceQueue = | 116 PersistentMemoryAllocator::kReferenceQueue = |
| 109 offsetof(SharedMetadata, queue); | 117 offsetof(SharedMetadata, queue); |
| 110 const PersistentMemoryAllocator::Reference | 118 const PersistentMemoryAllocator::Reference |
| 111 PersistentMemoryAllocator::kReferenceNull = 0; | 119 PersistentMemoryAllocator::kReferenceNull = 0; |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 FilePersistentMemoryAllocator::~FilePersistentMemoryAllocator() { | 669 FilePersistentMemoryAllocator::~FilePersistentMemoryAllocator() { |
| 662 } | 670 } |
| 663 | 671 |
| 664 // static | 672 // static |
| 665 bool FilePersistentMemoryAllocator::IsFileAcceptable( | 673 bool FilePersistentMemoryAllocator::IsFileAcceptable( |
| 666 const MemoryMappedFile& file) { | 674 const MemoryMappedFile& file) { |
| 667 return IsMemoryAcceptable(file.data(), file.length(), 0, true); | 675 return IsMemoryAcceptable(file.data(), file.length(), 0, true); |
| 668 } | 676 } |
| 669 | 677 |
| 670 } // namespace base | 678 } // namespace base |
| OLD | NEW |