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

Side by Side Diff: base/metrics/persistent_memory_allocator.h

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 unified diff | Download patch
OLDNEW
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 #include <atomic> 9 #include <atomic>
10 #include <string> 10 #include <string>
11 11
12 #include "base/atomicops.h" 12 #include "base/atomicops.h"
13 #include "base/base_export.h" 13 #include "base/base_export.h"
14 #include "base/gtest_prod_util.h" 14 #include "base/gtest_prod_util.h"
15 #include "base/macros.h" 15 #include "base/macros.h"
16 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
17 17
18 namespace base { 18 namespace base {
19 19
20 class HistogramBase; 20 class HistogramBase;
21 class MemoryMappedFile; 21 class MemoryMappedFile;
22 class SharedMemory;
22 23
23 // Simple allocator for pieces of a memory block that may be persistent 24 // Simple allocator for pieces of a memory block that may be persistent
24 // to some storage or shared across multiple processes. This class resides 25 // to some storage or shared across multiple processes. This class resides
25 // under base/metrics because it was written for that purpose. It is, 26 // under base/metrics because it was written for that purpose. It is,
26 // however, fully general-purpose and can be freely moved to base/memory 27 // however, fully general-purpose and can be freely moved to base/memory
27 // if other uses are found. 28 // if other uses are found.
28 // 29 //
29 // This class provides for thread-secure (i.e. safe against other threads 30 // This class provides for thread-secure (i.e. safe against other threads
30 // or processes that may be compromised and thus have malicious intent) 31 // or processes that may be compromised and thus have malicious intent)
31 // allocation of memory within a designated block and also a mechanism by 32 // allocation of memory within a designated block and also a mechanism by
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 public: 302 public:
302 LocalPersistentMemoryAllocator(size_t size, uint64_t id, 303 LocalPersistentMemoryAllocator(size_t size, uint64_t id,
303 const std::string& name); 304 const std::string& name);
304 ~LocalPersistentMemoryAllocator() override; 305 ~LocalPersistentMemoryAllocator() override;
305 306
306 private: 307 private:
307 DISALLOW_COPY_AND_ASSIGN(LocalPersistentMemoryAllocator); 308 DISALLOW_COPY_AND_ASSIGN(LocalPersistentMemoryAllocator);
308 }; 309 };
309 310
310 311
312 // This allocator takes a shared-memory object and performs allocation from
313 // it. The memory must be previously mapped via Map() or MapAt(). The allocator
314 // takes ownership of the memory object.
315 class BASE_EXPORT SharedPersistentMemoryAllocator
316 : public PersistentMemoryAllocator {
317 public:
318 SharedPersistentMemoryAllocator(scoped_ptr<SharedMemory> mem, uint64_t id,
Alexei Svitkine (slow) 2016/02/05 21:54:02 Nit: 1 param per line. |mem| -> |memory|
bcwhite 2016/02/06 04:26:11 Done.
319 const std::string& name, bool read_only);
320 ~SharedPersistentMemoryAllocator() override;
321
322 SharedMemory* GetSharedMemory() { return shared_memory_.get(); }
Alexei Svitkine (slow) 2016/02/05 21:54:02 Nit: Either a method is trivial and should be name
bcwhite 2016/02/06 04:26:11 Done.
323
324 // Ensure that the memory isn't so invalid that it won't crash when passing it
325 // to the allocator. This doesn't guarantee the data is valid, just that it
326 // won't cause the program to abort. The existing IsCorrupt() call will handle
327 // the rest.
328 static bool IsSharedMemoryAcceptable(const SharedMemory& mem);
Alexei Svitkine (slow) 2016/02/05 21:54:02 Hmm, it's hard to understand Acceptable without re
bcwhite 2016/02/06 04:26:11 It doesn't check that it's valid, just that it's a
329
330 private:
331 scoped_ptr<SharedMemory> shared_memory_;
Alexei Svitkine (slow) 2016/02/05 21:54:02 DISALLOW_COPY_AND_ASSIGN()
bcwhite 2016/02/06 04:26:11 I always forget that... below, too.
332 };
333
334
311 // This allocator takes a memory-mapped file object and performs allocation 335 // This allocator takes a memory-mapped file object and performs allocation
312 // from it. The allocator takes ownership of the file object. Only read access 336 // from it. The allocator takes ownership of the file object. Only read access
313 // is provided due to limitions of the MemoryMappedFile class. 337 // is provided due to limitions of the MemoryMappedFile class.
314 class BASE_EXPORT FilePersistentMemoryAllocator 338 class BASE_EXPORT FilePersistentMemoryAllocator
315 : public PersistentMemoryAllocator { 339 : public PersistentMemoryAllocator {
316 public: 340 public:
317 FilePersistentMemoryAllocator(MemoryMappedFile* file, uint64_t id, 341 FilePersistentMemoryAllocator(scoped_ptr<MemoryMappedFile> file, uint64_t id,
318 const std::string& name); 342 const std::string& name);
319 ~FilePersistentMemoryAllocator() override; 343 ~FilePersistentMemoryAllocator() override;
320 344
321 // Ensure that the file isn't so invalid that it won't crash when passing it 345 // Ensure that the file isn't so invalid that it won't crash when passing it
322 // to the allocator. This doesn't guarantee the file is valid, just that it 346 // to the allocator. This doesn't guarantee the file is valid, just that it
323 // won't cause program to abort. The existing IsCorrupt() call will handle 347 // won't cause the program to abort. The existing IsCorrupt() call will handle
324 // the rest. 348 // the rest.
325 static bool IsFileAcceptable(const MemoryMappedFile& file); 349 static bool IsFileAcceptable(const MemoryMappedFile& file);
326 350
327 private: 351 private:
328 scoped_ptr<MemoryMappedFile> mapped_file_; 352 scoped_ptr<MemoryMappedFile> mapped_file_;
329 }; 353 };
330 354
331 } // namespace base 355 } // namespace base
332 356
333 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ 357 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/persistent_memory_allocator.cc » ('j') | base/metrics/persistent_memory_allocator.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698