Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(427)

Unified Diff: base/metrics/persistent_memory_allocator.cc

Issue 2387733002: Move memory management code into separate class for future reuse. (Closed)
Patch Set: object_free -> object_free_type Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/metrics/persistent_memory_allocator.h ('k') | base/metrics/persistent_memory_allocator_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/metrics/persistent_memory_allocator.cc
diff --git a/base/metrics/persistent_memory_allocator.cc b/base/metrics/persistent_memory_allocator.cc
index fd8a73d0ad2921178fdca61e4becbd21e281c9d6..2b3bf17ede23881f963354138fa92c5ab994dbdd 100644
--- a/base/metrics/persistent_memory_allocator.cc
+++ b/base/metrics/persistent_memory_allocator.cc
@@ -133,7 +133,19 @@ PersistentMemoryAllocator::Iterator::Iterator(
PersistentMemoryAllocator::Iterator::Iterator(
const PersistentMemoryAllocator* allocator,
Reference starting_after)
- : allocator_(allocator), last_record_(starting_after), record_count_(0) {
+ : allocator_(allocator), last_record_(0), record_count_(0) {
+ Reset(starting_after);
+}
+
+void PersistentMemoryAllocator::Iterator::Reset() {
+ last_record_.store(kReferenceQueue, std::memory_order_relaxed);
+ record_count_.store(0, std::memory_order_relaxed);
+}
+
+void PersistentMemoryAllocator::Iterator::Reset(Reference starting_after) {
+ last_record_.store(starting_after, std::memory_order_relaxed);
+ record_count_.store(0, std::memory_order_relaxed);
+
// Ensure that the starting point is a valid, iterable block (meaning it can
// be read and has a non-zero "next" pointer).
const volatile BlockHeader* block =
@@ -145,6 +157,14 @@ PersistentMemoryAllocator::Iterator::Iterator(
}
PersistentMemoryAllocator::Reference
+PersistentMemoryAllocator::Iterator::GetLast() {
+ Reference last = last_record_.load(std::memory_order_relaxed);
+ if (last == kReferenceQueue)
+ return kReferenceNull;
+ return last;
+}
+
+PersistentMemoryAllocator::Reference
PersistentMemoryAllocator::Iterator::GetNext(uint32_t* type_return) {
// Make a copy of the existing count of found-records, acquiring all changes
// made to the allocator, notably "freeptr" (see comment in loop for why
« no previous file with comments | « base/metrics/persistent_memory_allocator.h ('k') | base/metrics/persistent_memory_allocator_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698