| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_ALLOCATOR_ALLOCATOR_SHIM_H_ | 5 #ifndef BASE_ALLOCATOR_ALLOCATOR_SHIM_H_ |
| 6 #define BASE_ALLOCATOR_ALLOCATOR_SHIM_H_ | 6 #define BASE_ALLOCATOR_ALLOCATOR_SHIM_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/base_export.h" | 10 #include "base/base_export.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 // ultimately routes the calls to the actual allocator defined by the build | 37 // ultimately routes the calls to the actual allocator defined by the build |
| 38 // config (tcmalloc, glibc, ...). | 38 // config (tcmalloc, glibc, ...). |
| 39 // | 39 // |
| 40 // It is possible to dynamically insert further AllocatorDispatch stages | 40 // It is possible to dynamically insert further AllocatorDispatch stages |
| 41 // to the front of the chain, for debugging / profiling purposes. | 41 // to the front of the chain, for debugging / profiling purposes. |
| 42 // | 42 // |
| 43 // All the functions must be thred safe. The shim does not enforce any | 43 // All the functions must be thred safe. The shim does not enforce any |
| 44 // serialization. This is to route to thread-aware allocators (e.g, tcmalloc) | 44 // serialization. This is to route to thread-aware allocators (e.g, tcmalloc) |
| 45 // wihout introducing unnecessary perf hits. | 45 // wihout introducing unnecessary perf hits. |
| 46 | 46 |
| 47 struct AllocatorDispatch { | 47 struct BASE_EXPORT AllocatorDispatch { |
| 48 using AllocFn = void*(const AllocatorDispatch* self, size_t size); | 48 using AllocFn = void*(const AllocatorDispatch* self, size_t size); |
| 49 using AllocZeroInitializedFn = void*(const AllocatorDispatch* self, | 49 using AllocZeroInitializedFn = void*(const AllocatorDispatch* self, |
| 50 size_t n, | 50 size_t n, |
| 51 size_t size); | 51 size_t size); |
| 52 using AllocAlignedFn = void*(const AllocatorDispatch* self, | 52 using AllocAlignedFn = void*(const AllocatorDispatch* self, |
| 53 size_t alignment, | 53 size_t alignment, |
| 54 size_t size); | 54 size_t size); |
| 55 using ReallocFn = void*(const AllocatorDispatch* self, | 55 using ReallocFn = void*(const AllocatorDispatch* self, |
| 56 void* address, | 56 void* address, |
| 57 size_t size); | 57 size_t size); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 | 94 |
| 95 // Test-only. Rationale: (1) lack of use cases; (2) dealing safely with a | 95 // Test-only. Rationale: (1) lack of use cases; (2) dealing safely with a |
| 96 // removal of arbitrary elements from a singly linked list would require a lock | 96 // removal of arbitrary elements from a singly linked list would require a lock |
| 97 // in malloc(), which we really don't want. | 97 // in malloc(), which we really don't want. |
| 98 BASE_EXPORT void RemoveAllocatorDispatchForTesting(AllocatorDispatch* dispatch); | 98 BASE_EXPORT void RemoveAllocatorDispatchForTesting(AllocatorDispatch* dispatch); |
| 99 | 99 |
| 100 } // namespace allocator | 100 } // namespace allocator |
| 101 } // namespace base | 101 } // namespace base |
| 102 | 102 |
| 103 #endif // BASE_ALLOCATOR_ALLOCATOR_SHIM_H_ | 103 #endif // BASE_ALLOCATOR_ALLOCATOR_SHIM_H_ |
| OLD | NEW |