File indexing completed on 2025-07-30 08:46:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017 #ifndef __TBB__small_object_pool_H
0018 #define __TBB__small_object_pool_H
0019
0020 #include "_config.h"
0021 #include "_assert.h"
0022
0023 #include "../profiling.h"
0024 #include <cstddef>
0025 #include <cstdint>
0026 #include <atomic>
0027
0028 namespace tbb {
0029 namespace detail {
0030
0031 namespace d1 {
0032 class small_object_pool {
0033 protected:
0034 small_object_pool() = default;
0035 };
0036 struct execution_data;
0037 }
0038
0039 namespace r1 {
0040 TBB_EXPORT void* __TBB_EXPORTED_FUNC allocate(d1::small_object_pool*& pool, std::size_t number_of_bytes,
0041 const d1::execution_data& ed);
0042 TBB_EXPORT void* __TBB_EXPORTED_FUNC allocate(d1::small_object_pool*& pool, std::size_t number_of_bytes);
0043 TBB_EXPORT void __TBB_EXPORTED_FUNC deallocate(d1::small_object_pool& pool, void* ptr, std::size_t number_of_bytes,
0044 const d1::execution_data& ed);
0045 TBB_EXPORT void __TBB_EXPORTED_FUNC deallocate(d1::small_object_pool& pool, void* ptr, std::size_t number_of_bytes);
0046 }
0047
0048 namespace d1 {
0049 class small_object_allocator {
0050 public:
0051 template <typename Type, typename... Args>
0052 Type* new_object(execution_data& ed, Args&&... args) {
0053 void* allocated_object = r1::allocate(m_pool, sizeof(Type), ed);
0054
0055 auto constructed_object = new(allocated_object) Type(std::forward<Args>(args)...);
0056 return constructed_object;
0057 }
0058
0059 template <typename Type, typename... Args>
0060 Type* new_object(Args&&... args) {
0061 void* allocated_object = r1::allocate(m_pool, sizeof(Type));
0062
0063 auto constructed_object = new(allocated_object) Type(std::forward<Args>(args)...);
0064 return constructed_object;
0065 }
0066
0067 template <typename Type>
0068 void delete_object(Type* object, const execution_data& ed) {
0069
0070
0071 small_object_allocator alloc = *this;
0072 object->~Type();
0073 alloc.deallocate(object, ed);
0074 }
0075
0076 template <typename Type>
0077 void delete_object(Type* object) {
0078
0079
0080 small_object_allocator alloc = *this;
0081 object->~Type();
0082 alloc.deallocate(object);
0083 }
0084
0085 template <typename Type>
0086 void deallocate(Type* ptr, const execution_data& ed) {
0087 call_itt_task_notify(destroy, ptr);
0088
0089 __TBB_ASSERT(m_pool != nullptr, "Pool must be valid for deallocate call");
0090 r1::deallocate(*m_pool, ptr, sizeof(Type), ed);
0091 }
0092
0093 template <typename Type>
0094 void deallocate(Type* ptr) {
0095 call_itt_task_notify(destroy, ptr);
0096
0097 __TBB_ASSERT(m_pool != nullptr, "Pool must be valid for deallocate call");
0098 r1::deallocate(*m_pool, ptr, sizeof(Type));
0099 }
0100 private:
0101 small_object_pool* m_pool{};
0102 };
0103
0104 }
0105 }
0106 }
0107
0108 #endif