| 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 #ifndef BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ | 5 #ifndef BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ |
| 6 #define BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ | 6 #define BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ |
| 7 | 7 |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <atomic> | 10 #include <atomic> |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 // the OS "pinning" new (zeroed) physical RAM pages only as they are needed. | 49 // the OS "pinning" new (zeroed) physical RAM pages only as they are needed. |
| 50 class BASE_EXPORT PersistentMemoryAllocator { | 50 class BASE_EXPORT PersistentMemoryAllocator { |
| 51 public: | 51 public: |
| 52 typedef uint32_t Reference; | 52 typedef uint32_t Reference; |
| 53 | 53 |
| 54 // Iterator for going through all iterable memory records in an allocator. | 54 // Iterator for going through all iterable memory records in an allocator. |
| 55 // Like the allocator itself, iterators are lock-free and thread-secure. | 55 // Like the allocator itself, iterators are lock-free and thread-secure. |
| 56 // That means that multiple threads can share an iterator and the same | 56 // That means that multiple threads can share an iterator and the same |
| 57 // reference will not be returned twice. | 57 // reference will not be returned twice. |
| 58 // | 58 // |
| 59 // The order of the items returned by an iterator matches the order in which |
| 60 // MakeIterable() was called on them. Once an allocation is made iterable, |
| 61 // it is always such so the only possible difference between successive |
| 62 // iterations is for more to be added to the end. |
| 63 // |
| 59 // Iteration, in general, is tolerant of corrupted memory. It will return | 64 // Iteration, in general, is tolerant of corrupted memory. It will return |
| 60 // what it can and stop only when corruption forces it to. Bad corruption | 65 // what it can and stop only when corruption forces it to. Bad corruption |
| 61 // could cause the same object to be returned many times but it will | 66 // could cause the same object to be returned many times but it will |
| 62 // eventually quit. | 67 // eventually quit. |
| 63 class BASE_EXPORT Iterator { | 68 class BASE_EXPORT Iterator { |
| 64 public: | 69 public: |
| 65 // Constructs an iterator on a given |allocator|, starting at the beginning. | 70 // Constructs an iterator on a given |allocator|, starting at the beginning. |
| 66 // The allocator must live beyond the lifetime of the iterator. This class | 71 // The allocator must live beyond the lifetime of the iterator. This class |
| 67 // has read-only access to the allocator (hence "const") but the returned | 72 // has read-only access to the allocator (hence "const") but the returned |
| 68 // references can be used on a read/write version, too. | 73 // references can be used on a read/write version, too. |
| 69 explicit Iterator(const PersistentMemoryAllocator* allocator); | 74 explicit Iterator(const PersistentMemoryAllocator* allocator); |
| 70 | 75 |
| 71 // As above but resuming from the |starting_after| reference. The first call | 76 // As above but resuming from the |starting_after| reference. The first call |
| 72 // to GetNext() will return the next object found after that reference. The | 77 // to GetNext() will return the next object found after that reference. The |
| 73 // reference must be to an "iterable" object; references to non-iterable | 78 // reference must be to an "iterable" object; references to non-iterable |
| 74 // objects (those that never had MakeIterable() called for them) will cause | 79 // objects (those that never had MakeIterable() called for them) will cause |
| 75 // a run-time error. | 80 // a run-time error. |
| 76 Iterator(const PersistentMemoryAllocator* allocator, | 81 Iterator(const PersistentMemoryAllocator* allocator, |
| 77 Reference starting_after); | 82 Reference starting_after); |
| 78 | 83 |
| 84 // Resets the iterator back to the beginning. |
| 85 void Reset(); |
| 86 |
| 87 // Resets the iterator, resuming from the |starting_after| reference. |
| 88 void Reset(Reference starting_after); |
| 89 |
| 90 // Returns the previously retrieved reference, or kReferenceNull if none. |
| 91 // If constructor or reset with a starting_after location, this will return |
| 92 // that value. |
| 93 Reference GetLast(); |
| 94 |
| 79 // Gets the next iterable, storing that type in |type_return|. The actual | 95 // Gets the next iterable, storing that type in |type_return|. The actual |
| 80 // return value is a reference to the allocation inside the allocator or | 96 // return value is a reference to the allocation inside the allocator or |
| 81 // zero if there are no more. GetNext() may still be called again at a | 97 // zero if there are no more. GetNext() may still be called again at a |
| 82 // later time to retrieve any new allocations that have been added. | 98 // later time to retrieve any new allocations that have been added. |
| 83 Reference GetNext(uint32_t* type_return); | 99 Reference GetNext(uint32_t* type_return); |
| 84 | 100 |
| 85 // Similar to above but gets the next iterable of a specific |type_match|. | 101 // Similar to above but gets the next iterable of a specific |type_match|. |
| 86 // This should not be mixed with calls to GetNext() because any allocations | 102 // This should not be mixed with calls to GetNext() because any allocations |
| 87 // skipped here due to a type mis-match will never be returned by later | 103 // skipped here due to a type mis-match will never be returned by later |
| 88 // calls to GetNext() meaning it's possible to completely miss entries. | 104 // calls to GetNext() meaning it's possible to completely miss entries. |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 443 private: | 459 private: |
| 444 std::unique_ptr<MemoryMappedFile> mapped_file_; | 460 std::unique_ptr<MemoryMappedFile> mapped_file_; |
| 445 | 461 |
| 446 DISALLOW_COPY_AND_ASSIGN(FilePersistentMemoryAllocator); | 462 DISALLOW_COPY_AND_ASSIGN(FilePersistentMemoryAllocator); |
| 447 }; | 463 }; |
| 448 #endif // !defined(OS_NACL) | 464 #endif // !defined(OS_NACL) |
| 449 | 465 |
| 450 } // namespace base | 466 } // namespace base |
| 451 | 467 |
| 452 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ | 468 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ |
| OLD | NEW |