From 1c75653678541e5765330ccfcf300c4125a34dbd Mon Sep 17 00:00:00 2001 From: Rodrigo Kumpera Date: Thu, 29 May 2014 21:51:29 -0400 Subject: [PATCH] Implement the finalization extension API (Apply commit c429e9f from 'mono_libgc' branch.) Conflicts: finalize.c include/gc.h --- finalize.c | 13 +++++++++++++ include/gc.h | 3 +++ 2 files changed, 16 insertions(+) diff --git a/finalize.c b/finalize.c index c2e8af02..33bac249 100644 --- a/finalize.c +++ b/finalize.c @@ -263,6 +263,15 @@ GC_API int GC_CALL GC_unregister_disappearing_link(void * * link) return 1; } +/* Finalizer proc support */ +static void (*GC_object_finalized_proc) (GC_PTR obj); + +void +GC_set_finalizer_notify_proc (void (*proc) (GC_PTR obj)) +{ + GC_object_finalized_proc = proc; +} + #ifndef GC_LONG_REFS_NOT_NEEDED GC_API int GC_CALL GC_register_long_link(void * * link, const void * obj) { @@ -788,6 +797,10 @@ GC_INNER void GC_finalize(void) fo_set_next(prev_fo, next_fo); } GC_fo_entries--; + + if (GC_object_finalized_proc) + GC_object_finalized_proc (real_ptr); + /* Add to list of objects awaiting finalization. */ fo_set_next(curr_fo, GC_finalize_now); GC_finalize_now = curr_fo; diff --git a/include/gc.h b/include/gc.h index ad5da167..6a6e0edd 100644 --- a/include/gc.h +++ b/include/gc.h @@ -1172,6 +1172,9 @@ GC_API int GC_CALL GC_unregister_long_link(void ** /* link */); /* Similar to GC_unregister_disappearing_link but for a */ /* registration by either of the above two routines. */ +/* finalizer callback support */ +GC_API void GC_set_finalizer_notify_proc GC_PROTO((void (*object_finalized) (GC_PTR obj))); + /* Returns !=0 if GC_invoke_finalizers has something to do. */ GC_API int GC_CALL GC_should_invoke_finalizers(void); -- 2.40.0