Implement the finalization extension API
authorRodrigo Kumpera <kumpera@gmail.com>
Fri, 30 May 2014 01:51:29 +0000 (21:51 -0400)
committerIvan Maidanski <ivmai@mail.ru>
Thu, 16 Jul 2015 22:05:38 +0000 (01:05 +0300)
(Apply commit c429e9f from 'mono_libgc' branch.)

Conflicts:

    finalize.c
    include/gc.h

finalize.c
include/gc.h

index c2e8af0..33bac24 100644 (file)
@@ -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;
index ad5da16..6a6e0ed 100644 (file)
@@ -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);