]> granicus.if.org Git - gc/commitdiff
Code refactoring of 'finalization extension API'
authorIvan Maidanski <ivmai@mail.ru>
Sun, 19 Jul 2015 14:14:16 +0000 (17:14 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Sun, 19 Jul 2015 14:14:16 +0000 (17:14 +0300)
* finalize.c (GC_object_finalized_proc, GC_set_finalizer_notify_proc):
Use GC_await_finalize_proc type.
* finalize.c (GC_object_finalized_proc): Use STATIC instead of
"static".
* finalize.c (GC_set_finalizer_notify_proc): Rename to
GC_set_await_finalize_proc.
* include/gc.h (GC_set_finalizer_notify_proc): Likewise.
* finalize.c (GC_set_await_finalize_proc): Add LOCK/UNLOCK.
* finalize.c (GC_set_await_finalize_proc): Decorate with GC_CALL.
* include/gc.h (GC_set_await_finalize_proc): Likewise.
* finalize.c (GC_get_await_finalize_proc): New API function.
* include/gc.h (GC_await_finalize_proc): New type.
* include/gc.h (GC_set_await_finalize_proc): Document.
* include/gc.h (GC_get_await_finalize_proc): New API function
declaration.

finalize.c
include/gc.h

index 33bac2490b362d63e633c6443a38dcc5f6ac656d..26adb11c228d8d14e8670d67b212e2ababd4501d 100644 (file)
@@ -263,13 +263,27 @@ 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);
+/* Finalizer callback support. */
+STATIC GC_await_finalize_proc GC_object_finalized_proc = 0;
 
-void
-GC_set_finalizer_notify_proc (void (*proc) (GC_PTR obj))
+GC_API void GC_CALL GC_set_await_finalize_proc(GC_await_finalize_proc fn)
 {
-    GC_object_finalized_proc = proc;
+  DCL_LOCK_STATE;
+
+  LOCK();
+  GC_object_finalized_proc = fn;
+  UNLOCK();
+}
+
+GC_API GC_await_finalize_proc GC_CALL GC_get_await_finalize_proc(void)
+{
+  GC_await_finalize_proc fn;
+  DCL_LOCK_STATE;
+
+  LOCK();
+  fn = GC_object_finalized_proc;
+  UNLOCK();
+  return fn;
 }
 
 #ifndef GC_LONG_REFS_NOT_NEEDED
@@ -797,9 +811,8 @@ 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);
+                GC_object_finalized_proc(real_ptr);
 
             /* Add to list of objects awaiting finalization.    */
               fo_set_next(curr_fo, GC_finalize_now);
index 6a6e0edd85e57e2ca7ceef3b339997189f2ef2ac..a52408af0eb3396d259c279593b74974c8b6da8b 100644 (file)
@@ -1172,8 +1172,14 @@ 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)));
+/* Finalizer callback support.  Invoked by the collector (with  */
+/* the allocation lock held) for each unreachable object        */
+/* enqueued for finalization.                                   */
+typedef void (GC_CALLBACK * GC_await_finalize_proc)(void * /* obj */);
+GC_API void GC_CALL GC_set_await_finalize_proc(GC_await_finalize_proc);
+GC_API GC_await_finalize_proc GC_CALL GC_get_await_finalize_proc(void);
+                        /* Zero means no callback.  The setter  */
+                        /* and getter acquire the lock too.     */
 
 /* Returns !=0 if GC_invoke_finalizers has something to do.     */
 GC_API int GC_CALL GC_should_invoke_finalizers(void);