5 #ifndef INCLUDE_CPPGC_INTERNAL_GC_INFO_H_
6 #define INCLUDE_CPPGC_INTERNAL_GC_INFO_H_
10 #include <type_traits>
12 #include "cppgc/internal/finalizer-trait.h"
13 #include "cppgc/internal/name-trait.h"
14 #include "cppgc/trace-trait.h"
20 using GCInfoIndex = uint16_t;
27 std::atomic<GCInfoIndex>& registered_index) {
28 return EnsureGCInfoIndexTraitDispatch<T>{}(registered_index);
32 template <
typename T,
bool = std::is_polymorphic<T>::value,
34 bool = NameTrait<T>::HasNonHiddenName()>
35 struct EnsureGCInfoIndexTraitDispatch;
37 static GCInfoIndex EnsureGCInfoIndexPolymorphic(std::atomic<GCInfoIndex>&,
41 static GCInfoIndex EnsureGCInfoIndexPolymorphic(std::atomic<GCInfoIndex>&,
43 FinalizationCallback);
44 static GCInfoIndex EnsureGCInfoIndexPolymorphic(std::atomic<GCInfoIndex>&,
45 TraceCallback, NameCallback);
46 static GCInfoIndex EnsureGCInfoIndexPolymorphic(std::atomic<GCInfoIndex>&,
48 static GCInfoIndex EnsureGCInfoIndexNonPolymorphic(std::atomic<GCInfoIndex>&,
53 static GCInfoIndex EnsureGCInfoIndexNonPolymorphic(std::atomic<GCInfoIndex>&,
55 FinalizationCallback);
56 static GCInfoIndex EnsureGCInfoIndexNonPolymorphic(std::atomic<GCInfoIndex>&,
59 static GCInfoIndex EnsureGCInfoIndexNonPolymorphic(std::atomic<GCInfoIndex>&,
63 #define DISPATCH(is_polymorphic, has_finalizer, has_non_hidden_name, function)
65 struct EnsureGCInfoIndexTrait::EnsureGCInfoIndexTraitDispatch<
66 T, is_polymorphic, has_finalizer, has_non_hidden_name> {
68 operator
()(std::atomic<GCInfoIndex>& registered_index) {
77 EnsureGCInfoIndexPolymorphic(registered_index,
80 NameTrait<T>::GetName))
82 EnsureGCInfoIndexPolymorphic(registered_index,
86 EnsureGCInfoIndexPolymorphic(registered_index,
88 NameTrait<T>::GetName))
90 EnsureGCInfoIndexPolymorphic(registered_index,
93 EnsureGCInfoIndexNonPolymorphic(registered_index,
96 NameTrait<T>::GetName))
98 EnsureGCInfoIndexNonPolymorphic(registered_index,
102 EnsureGCInfoIndexNonPolymorphic(registered_index,
104 NameTrait<T>::GetName))
106 EnsureGCInfoIndexNonPolymorphic(registered_index,
114 template <
typename T,
typename ParentMostGarbageCollectedType>
117 std::has_virtual_destructor<ParentMostGarbageCollectedType>::value;
119 std::is_trivially_destructible<ParentMostGarbageCollectedType>::value &&
120 std::is_trivially_destructible<T>::value;
123 ParentMostGarbageCollectedType>::value;
124 #ifdef CPPGC_SUPPORTS_OBJECT_NAMES
136 ParentMostGarbageCollectedType, T>;
141 template <
typename T>
142 struct GCInfoTrait
final {
144 static_assert(
sizeof(T),
"T must be fully defined");
145 static std::atomic<GCInfoIndex>
147 const GCInfoIndex index = registered_index.load(std::memory_order_acquire);
149 : EnsureGCInfoIndexTrait::EnsureIndex<T>(registered_index);