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

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

Issue 2534643002: Add support for turning pointers back to references. (Closed)
Patch Set: added underflow check Created 4 years 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
« no previous file with comments | « no previous file | base/metrics/persistent_memory_allocator.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 9
10 #include <atomic> 10 #include <atomic>
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 return const_cast<T*>(reinterpret_cast<volatile T*>( 309 return const_cast<T*>(reinterpret_cast<volatile T*>(
310 GetBlockData(ref, type_id, count * sizeof(T)))); 310 GetBlockData(ref, type_id, count * sizeof(T))));
311 } 311 }
312 template <typename T> 312 template <typename T>
313 const T* GetAsArray(Reference ref, uint32_t type_id, size_t count) const { 313 const T* GetAsArray(Reference ref, uint32_t type_id, size_t count) const {
314 static_assert(std::is_fundamental<T>::value, "use GetAsObject<>()"); 314 static_assert(std::is_fundamental<T>::value, "use GetAsObject<>()");
315 return const_cast<const char*>(reinterpret_cast<const volatile T*>( 315 return const_cast<const char*>(reinterpret_cast<const volatile T*>(
316 GetBlockData(ref, type_id, count * sizeof(T)))); 316 GetBlockData(ref, type_id, count * sizeof(T))));
317 } 317 }
318 318
319 // Get the corresponding reference for an object held in persistent memory.
320 // If the |memory| is not valid or the type does not match, a kReferenceNull
321 // result will be returned.
322 Reference GetAsReference(const void* memory, uint32_t type_id) const;
323
319 // Get the number of bytes allocated to a block. This is useful when storing 324 // Get the number of bytes allocated to a block. This is useful when storing
320 // arrays in order to validate the ending boundary. The returned value will 325 // arrays in order to validate the ending boundary. The returned value will
321 // include any padding added to achieve the required alignment and so could 326 // include any padding added to achieve the required alignment and so could
322 // be larger than given in the original Allocate() request. 327 // be larger than given in the original Allocate() request.
323 size_t GetAllocSize(Reference ref) const; 328 size_t GetAllocSize(Reference ref) const;
324 329
325 // Access the internal "type" of an object. This generally isn't necessary 330 // Access the internal "type" of an object. This generally isn't necessary
326 // but can be used to "clear" the type and so effectively mark it as deleted 331 // but can be used to "clear" the type and so effectively mark it as deleted
327 // even though the memory stays valid and allocated. Changing the type is 332 // even though the memory stays valid and allocated. Changing the type is
328 // an atomic compare/exchange and so requires knowing the existing value. 333 // an atomic compare/exchange and so requires knowing the existing value.
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 private: 531 private:
527 std::unique_ptr<MemoryMappedFile> mapped_file_; 532 std::unique_ptr<MemoryMappedFile> mapped_file_;
528 533
529 DISALLOW_COPY_AND_ASSIGN(FilePersistentMemoryAllocator); 534 DISALLOW_COPY_AND_ASSIGN(FilePersistentMemoryAllocator);
530 }; 535 };
531 #endif // !defined(OS_NACL) 536 #endif // !defined(OS_NACL)
532 537
533 } // namespace base 538 } // namespace base
534 539
535 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ 540 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_
OLDNEW
« no previous file with comments | « no previous file | base/metrics/persistent_memory_allocator.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698