5 #ifndef INCLUDE_CPPGC_PREFINALIZER_H_
6 #define INCLUDE_CPPGC_PREFINALIZER_H_
8 #include "cppgc/internal/accessors.h"
9 #include "cppgc/internal/compiler-specific.h"
10 #include "cppgc/internal/prefinalizer-handler.h"
11 #include "cppgc/liveness-broker.h"
12 #include "cppgc/macros.h"
19 class PrefinalizerRegistration final {
22 static_assert(
sizeof(&T::InvokePreFinalizer) > 0,
23 "USING_PRE_FINALIZER(T) must be defined.");
29 void*
operator new(size_t,
void* location) =
delete;
35 #define CPPGC_USING_PRE_FINALIZER(Class, PreFinalizer)
37 static bool InvokePreFinalizer(const LivenessBroker& liveness_broker,
39 static_assert(internal::IsGarbageCollectedTypeV<Class>,
40 "Only garbage collected objects can have prefinalizers");
41 Class* self = static_cast<Class*>(object);
42 if (liveness_broker.IsHeapObjectAlive(self)) return false;
43 self->Class::PreFinalizer();
49 prefinalizer_dummy_{this};
50 friend class internal::__thisIsHereToForceASemicolonAfterThisMacro