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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 } | 234 } |
235 | 235 |
236 // Get the number of bytes allocated to a block. This is useful when storing | 236 // Get the number of bytes allocated to a block. This is useful when storing |
237 // arrays in order to validate the ending boundary. The returned value will | 237 // arrays in order to validate the ending boundary. The returned value will |
238 // include any padding added to achieve the required alignment and so could | 238 // include any padding added to achieve the required alignment and so could |
239 // be larger than given in the original Allocate() request. | 239 // be larger than given in the original Allocate() request. |
240 size_t GetAllocSize(Reference ref) const; | 240 size_t GetAllocSize(Reference ref) const; |
241 | 241 |
242 // Access the internal "type" of an object. This generally isn't necessary | 242 // Access the internal "type" of an object. This generally isn't necessary |
243 // but can be used to "clear" the type and so effectively mark it as deleted | 243 // but can be used to "clear" the type and so effectively mark it as deleted |
244 // even though the memory stays valid and allocated. | 244 // even though the memory stays valid and allocated. Changing the type is |
| 245 // an atomic compare/exchange and so requires knowing the existing value. |
| 246 // It will return false if the existing type is not what is expected. |
245 uint32_t GetType(Reference ref) const; | 247 uint32_t GetType(Reference ref) const; |
246 void SetType(Reference ref, uint32_t type_id); | 248 bool ChangeType(Reference ref, uint32_t to_type_id, uint32_t from_type_id); |
247 | 249 |
248 // Reserve space in the memory segment of the desired |size| and |type_id|. | 250 // Reserve space in the memory segment of the desired |size| and |type_id|. |
249 // A return value of zero indicates the allocation failed, otherwise the | 251 // A return value of zero indicates the allocation failed, otherwise the |
250 // returned reference can be used by any process to get a real pointer via | 252 // returned reference can be used by any process to get a real pointer via |
251 // the GetAsObject() call. | 253 // the GetAsObject() call. |
252 Reference Allocate(size_t size, uint32_t type_id); | 254 Reference Allocate(size_t size, uint32_t type_id); |
253 | 255 |
254 // Allocated objects can be added to an internal list that can then be | 256 // Allocated objects can be added to an internal list that can then be |
255 // iterated over by other processes. If an allocated object can be found | 257 // iterated over by other processes. If an allocated object can be found |
256 // another way, such as by having its reference within a different object | 258 // another way, such as by having its reference within a different object |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 | 410 |
409 private: | 411 private: |
410 std::unique_ptr<MemoryMappedFile> mapped_file_; | 412 std::unique_ptr<MemoryMappedFile> mapped_file_; |
411 | 413 |
412 DISALLOW_COPY_AND_ASSIGN(FilePersistentMemoryAllocator); | 414 DISALLOW_COPY_AND_ASSIGN(FilePersistentMemoryAllocator); |
413 }; | 415 }; |
414 | 416 |
415 } // namespace base | 417 } // namespace base |
416 | 418 |
417 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ | 419 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ |
OLD | NEW |