| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 size_t total; | 210 size_t total; |
| 211 size_t free; | 211 size_t free; |
| 212 }; | 212 }; |
| 213 | 213 |
| 214 enum : Reference { | 214 enum : Reference { |
| 215 // A common "null" reference value. | 215 // A common "null" reference value. |
| 216 kReferenceNull = 0, | 216 kReferenceNull = 0, |
| 217 }; | 217 }; |
| 218 | 218 |
| 219 enum : uint32_t { | 219 enum : uint32_t { |
| 220 // A value that will match any type when doing lookups. |
| 221 kTypeIdAny = 0x00000000, |
| 222 |
| 220 // A value indicating that the type is in transition. Work is being done | 223 // A value indicating that the type is in transition. Work is being done |
| 221 // on the contents to prepare it for a new type to come. | 224 // on the contents to prepare it for a new type to come. |
| 222 kTypeIdTransitioning = 0xFFFFFFFF, | 225 kTypeIdTransitioning = 0xFFFFFFFF, |
| 223 }; | 226 }; |
| 224 | 227 |
| 225 enum : size_t { | 228 enum : size_t { |
| 226 kSizeAny = 1 // Constant indicating that any array size is acceptable. | 229 kSizeAny = 1 // Constant indicating that any array size is acceptable. |
| 227 }; | 230 }; |
| 228 | 231 |
| 229 // This is the standard file extension (suitable for being passed to the | 232 // This is the standard file extension (suitable for being passed to the |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 393 | 396 |
| 394 // Access the internal "type" of an object. This generally isn't necessary | 397 // Access the internal "type" of an object. This generally isn't necessary |
| 395 // but can be used to "clear" the type and so effectively mark it as deleted | 398 // but can be used to "clear" the type and so effectively mark it as deleted |
| 396 // even though the memory stays valid and allocated. Changing the type is | 399 // even though the memory stays valid and allocated. Changing the type is |
| 397 // an atomic compare/exchange and so requires knowing the existing value. | 400 // an atomic compare/exchange and so requires knowing the existing value. |
| 398 // It will return false if the existing type is not what is expected. | 401 // It will return false if the existing type is not what is expected. |
| 399 // | 402 // |
| 400 // Changing the type doesn't mean the data is compatible with the new type. | 403 // Changing the type doesn't mean the data is compatible with the new type. |
| 401 // Passing true for |clear| will zero the memory after the type has been | 404 // Passing true for |clear| will zero the memory after the type has been |
| 402 // changed away from |from_type_id| but before it becomes |to_type_id| meaning | 405 // changed away from |from_type_id| but before it becomes |to_type_id| meaning |
| 403 // that it is done in a manner that is thread-safe. | 406 // that it is done in a manner that is thread-safe. Memory is guaranteed to |
| 407 // be zeroed atomically by machine-word in a monotonically increasing order. |
| 404 // | 408 // |
| 405 // It will likely be necessary to reconstruct the type before it can be used. | 409 // It will likely be necessary to reconstruct the type before it can be used. |
| 406 // Changing the type WILL NOT invalidate existing pointers to the data, either | 410 // Changing the type WILL NOT invalidate existing pointers to the data, either |
| 407 // in this process or others, so changing the data structure could have | 411 // in this process or others, so changing the data structure could have |
| 408 // unpredicatable results. USE WITH CARE! | 412 // unpredicatable results. USE WITH CARE! |
| 409 uint32_t GetType(Reference ref) const; | 413 uint32_t GetType(Reference ref) const; |
| 410 bool ChangeType(Reference ref, | 414 bool ChangeType(Reference ref, |
| 411 uint32_t to_type_id, | 415 uint32_t to_type_id, |
| 412 uint32_t from_type_id, | 416 uint32_t from_type_id, |
| 413 bool clear); | 417 bool clear); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 private: | 718 private: |
| 715 std::unique_ptr<MemoryMappedFile> mapped_file_; | 719 std::unique_ptr<MemoryMappedFile> mapped_file_; |
| 716 | 720 |
| 717 DISALLOW_COPY_AND_ASSIGN(FilePersistentMemoryAllocator); | 721 DISALLOW_COPY_AND_ASSIGN(FilePersistentMemoryAllocator); |
| 718 }; | 722 }; |
| 719 #endif // !defined(OS_NACL) | 723 #endif // !defined(OS_NACL) |
| 720 | 724 |
| 721 } // namespace base | 725 } // namespace base |
| 722 | 726 |
| 723 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ | 727 #endif // BASE_METRICS_PERSISTENT_MEMORY_ALLOCATOR_H_ |
| OLD | NEW |