]> granicus.if.org Git - gc/commitdiff
Added getters for exit and abort callback hooks.
authorJean-Claude Beaudoin <jean.claude.beaudoin@gmail.com>
Sun, 24 Jun 2012 04:08:50 +0000 (00:08 -0400)
committerJean-Claude Beaudoin <jean.claude.beaudoin@gmail.com>
Sun, 24 Jun 2012 04:08:50 +0000 (00:08 -0400)
include/gc.h
misc.c

index 42c205a081fc5dcc398281359feebca088451de5..9cbc560ac7167ceefad4c577a28502bcc1e63196 100644 (file)
@@ -1614,10 +1614,12 @@ GC_API void GC_CALL GC_win32_free_heap(void);
 typedef void (GC_CALLBACK * GC_exit_func)(int /* status */);
 
 GC_API void GC_CALL GC_set_exit_func(GC_exit_func);
+GC_API GC_exit_func GC_CALL GC_get_exit_func(void);
 
-typedef void (GC_CALLBACK * GC_abort_func)(char * /* msg */);
+typedef void (GC_CALLBACK * GC_abort_func)(const char * /* msg */);
 
 GC_API void GC_CALL GC_set_abort_func(GC_abort_func);
+GC_API GC_abort_func GC_CALL GC_get_abort_func(void);
 
 #ifdef __cplusplus
   }  /* end of extern "C" */
diff --git a/misc.c b/misc.c
index 79c88bde7d867de3135a1dbe69908892d697a55e..443c2385637813899b211da753e6507bb40e67e5 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -1454,12 +1454,28 @@ STATIC GC_abort_func abort_fn = NULL;
 
 GC_API void GC_CALL GC_set_abort_func(GC_abort_func fn)
 {
-  abort_fn = fn;
+    GC_ASSERT(fn != 0);
+    DCL_LOCK_STATE;
+    LOCK();
+    abort_fn = fn;
+    UNLOCK();
+}
+
+GC_API GC_abort_func GC_CALL GC_get_abort_func(void)
+{
+    GC_abort_func fn;
+    DCL_LOCK_STATE;
+    LOCK();
+    fn = abort_fn;
+    UNLOCK();
+    return fn;
 }
 
 
 #if !defined(PCR) && !defined(SMALL_CONFIG)
-  /* Print (or display) a message before abort. msg must not be NULL. */
+  /* Call abort callback with msg as argument,           */
+  /* and then print (or display) a message before abort. */
+  /* msg must not be NULL.                               */
   void GC_on_abort(const char *msg)
   {
     if (abort_fn) abort_fn(msg);
@@ -1501,7 +1517,7 @@ GC_API void GC_CALL GC_set_abort_func(GC_abort_func fn)
 
 STATIC GC_exit_func exit_fn = NULL;
 
-void GC_exit(int status)
+GC_API_PRIV void GC_exit(int status)
 {
   if (exit_fn) exit_fn(status);
   (void) exit(status);
@@ -1509,7 +1525,21 @@ void GC_exit(int status)
 
 GC_API void GC_CALL GC_set_exit_func(GC_exit_func fn)
 {
-  exit_fn = fn;
+    GC_ASSERT(fn != 0);
+    DCL_LOCK_STATE;
+    LOCK();
+    exit_fn = fn;
+    UNLOCK();
+}
+
+GC_API GC_exit_func GC_CALL GC_get_exit_func(void)
+{
+    GC_exit_func fn;
+    DCL_LOCK_STATE;
+    LOCK();
+    fn = exit_fn;
+    UNLOCK();
+    return fn;
 }