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

Unified Diff: base/metrics/persistent_memory_allocator.cc

Issue 1660143009: Add SharedMemory version of PersistentMemoryAllocator. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix signed/unsigned comparison in test and fixed ownership move in release build Created 4 years, 10 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
Index: base/metrics/persistent_memory_allocator.cc
diff --git a/base/metrics/persistent_memory_allocator.cc b/base/metrics/persistent_memory_allocator.cc
index 8b4c4a4cd759758d64623d19e36f1067f24adeb8..599e0de2984b04179380b4b00b626f914c444341 100644
--- a/base/metrics/persistent_memory_allocator.cc
+++ b/base/metrics/persistent_memory_allocator.cc
@@ -9,6 +9,7 @@
#include "base/files/memory_mapped_file.h"
#include "base/logging.h"
+#include "base/memory/shared_memory.h"
#include "base/metrics/histogram_macros.h"
namespace {
@@ -207,6 +208,15 @@ PersistentMemoryAllocator::PersistentMemoryAllocator(void* base,
strcpy(name_cstr, name.c_str());
}
} else {
+ if (shared_meta()->size == 0 ||
+ shared_meta()->version == 0 ||
+ shared_meta()->freeptr.load() == 0 ||
+ shared_meta()->tailptr == 0 ||
+ shared_meta()->queue.cookie == 0 ||
+ shared_meta()->queue.next.load() == 0) {
+ NOTREACHED();
+ SetCorrupt();
+ }
if (readonly) {
// For read-only access, validate reasonable ctor parameters.
DCHECK_GE(mem_size_, shared_meta()->freeptr.load());
@@ -648,15 +658,36 @@ LocalPersistentMemoryAllocator::~LocalPersistentMemoryAllocator() {
}
+//----- SharedPersistentMemoryAllocator ----------------------------------------
+
+SharedPersistentMemoryAllocator::SharedPersistentMemoryAllocator(
+ scoped_ptr<SharedMemory> shmem,
Alexei Svitkine (slow) 2016/02/05 21:54:02 Nit: Make param consistent with header.
bcwhite 2016/02/06 04:26:11 Done.
+ uint64_t id,
+ const std::string& name,
+ bool read_only)
+ : PersistentMemoryAllocator(static_cast<uint8_t*>(shmem->memory()),
+ shmem->mapped_size(), 0, id, name, read_only),
+ shared_memory_(std::move(shmem)) {}
+
+SharedPersistentMemoryAllocator::~SharedPersistentMemoryAllocator() {
+}
+
+// static
+bool SharedPersistentMemoryAllocator::IsSharedMemoryAcceptable(
+ const SharedMemory& shmem) {
+ return IsMemoryAcceptable(shmem.memory(), shmem.mapped_size(), 0, true);
+}
+
+
//----- FilePersistentMemoryAllocator ------------------------------------------
FilePersistentMemoryAllocator::FilePersistentMemoryAllocator(
- MemoryMappedFile* file,
+ scoped_ptr<MemoryMappedFile> file,
uint64_t id,
const std::string& name)
: PersistentMemoryAllocator(const_cast<uint8_t*>(file->data()),
file->length(), 0, id, name, true),
- mapped_file_(file) {}
+ mapped_file_(std::move(file)) {}
FilePersistentMemoryAllocator::~FilePersistentMemoryAllocator() {
}

Powered by Google App Engine
This is Rietveld 408576698