From: Jean-Claude Beaudoin Date: Sun, 24 Jun 2012 04:08:50 +0000 (-0400) Subject: Added getters for exit and abort callback hooks. X-Git-Tag: gc7_4_0~263^2^2~1 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=60f42cee18db2b541d2507cf57d7ea6893ecad9c;p=gc Added getters for exit and abort callback hooks. --- diff --git a/include/gc.h b/include/gc.h index 42c205a0..9cbc560a 100644 --- a/include/gc.h +++ b/include/gc.h @@ -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 79c88bde..443c2385 100644 --- 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; }