From: Jean-Claude Beaudoin Date: Sun, 24 Jun 2012 07:15:46 +0000 (-0400) Subject: Segregated suspend/restart signal init changes into their own branch. X-Git-Tag: gc7_4_0~261^2^2~3 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5c2a3a48c2ce6b26b37eab05db88d00d9d265c15;p=gc Segregated suspend/restart signal init changes into their own branch. --- diff --git a/include/gc.h b/include/gc.h index ba0962db..1cc39291 100644 --- a/include/gc.h +++ b/include/gc.h @@ -1131,13 +1131,21 @@ GC_API void * GC_CALL GC_call_with_stack_base(GC_stack_base_func /* fn */, #endif #ifdef GC_THREADS - /* Return the signal number (constant) used by the garbage collector */ + /* Return the signal number (constant after init) used by the GC */ /* to suspend threads on POSIX systems. Return -1 otherwise. */ GC_API int GC_CALL GC_get_suspend_signal(void); + /* Sets the signal number (constant after init) used by the GC */ + /* to suspend threads on POSIX systems. */ + /* Effective only when used before GC_init(). */ + GC_API void GC_CALL GC_set_suspend_signal(int sig); - /* Return the signal number (constant) used by the garbage collector */ + /* Return the signal number (constant after init) used by the GC */ /* to restart (resume) threads on POSIX systems. Return -1 otherwise. */ GC_API int GC_CALL GC_get_thr_restart_signal(void); + /* Sets the signal number (constant after init) used by the GC */ + /* to restart (resume) threads on POSIX systems. */ + /* Effective only when used before GC_init(). */ + GC_API void GC_CALL GC_set_thr_restart_signal(int sig); /* Explicitly enable GC_register_my_thread() invocation. */ /* Done implicitly if a GC thread-creation function is called (or */ @@ -1610,21 +1618,6 @@ GC_API void GC_CALL GC_win32_free_heap(void); (*GC_amiga_allocwrapper_do)(a,GC_malloc_atomic_ignore_off_page) #endif /* _AMIGA && !GC_AMIGA_MAKINGLIB */ - -typedef void (GC_CALLBACK * GC_exit_func)(const int status); - -GC_API void GC_CALL GC_set_exit_func(GC_exit_func fn); - -typedef void (GC_CALLBACK * GC_abort_func)(const char * const msg); - -GC_API void GC_CALL GC_set_abort_func(GC_abort_func fn); - -#if defined(GC_LINUX_THREADS) -GC_API void GC_CALL GC_set_suspend_signal(const int sig); -GC_API void GC_CALL GC_set_thr_restart_signal(const int sig); -#endif - - #ifdef __cplusplus } /* end of extern "C" */ #endif diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 91695132..578a1e2b 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -493,8 +493,7 @@ typedef char * ptr_t; /* A generic pointer to which we can add */ # ifdef PCR # define EXIT() PCR_Base_Exit(1,PCR_waitForever) # else - GC_API_PRIV void GC_exit(int status); -# define EXIT() GC_exit(1) +# define EXIT() (void)exit(1) # endif /* Print warning message, e.g. almost out of memory. */ diff --git a/misc.c b/misc.c index 7ae02f5b..7c418cf2 100644 --- a/misc.c +++ b/misc.c @@ -509,39 +509,43 @@ GC_API void GC_CALL GC_get_heap_usage_safe(GC_word *pheap_size, #ifdef THREADS +# ifdef SIG_SUSPEND_DEFAULT STATIC int suspend_signal = SIG_SUSPEND_DEFAULT; +# else +STATIC int suspend_signal = -1; +# endif +# ifdef SIG_THR_RESTART_DEFAULT STATIC int thread_restart_signal = SIG_THR_RESTART_DEFAULT; +# else +STATIC int thread_restart_signal = -1; +# endif -void GC_set_suspend_signal(const int sig) +GC_API void GC_CALL GC_set_suspend_signal(int sig) { +# ifdef SIG_SUSPEND_DEFAULT if (GC_is_initialized) return; suspend_signal = sig; +# endif } -void GC_set_thread_restart_signal(const int sig) +GC_API void GC_CALL GC_set_thread_restart_signal(int sig) { +# ifdef SIG_THR_RESTART_DEFAULT if (GC_is_initialized) return; thread_restart_signal = sig; +# endif } - GC_API int GC_CALL GC_get_suspend_signal(void) - { -# ifdef SIG_SUSPEND - return suspend_signal; -# else - return -1; -# endif - } +GC_API int GC_CALL GC_get_suspend_signal(void) +{ + return suspend_signal; +} - GC_API int GC_CALL GC_get_thr_restart_signal(void) - { -# ifdef SIG_THR_RESTART - return thread_restart_signal; -# else - return -1; /* GC does not use signals to restart threads. */ -# endif - } +GC_API int GC_CALL GC_get_thr_restart_signal(void) +{ + return thread_restart_signal; +} #endif /* THREADS */ @@ -1478,19 +1482,10 @@ GC_API GC_warn_proc GC_CALL GC_get_warn_proc(void) return(result); } -STATIC GC_abort_func abort_fn = NULL; /* JCB */ - -GC_API void GC_CALL GC_set_abort_func(GC_abort_func fn) -{ - abort_fn = fn; -} - - #if !defined(PCR) && !defined(SMALL_CONFIG) /* 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); # if defined(MSWIN32) # ifndef DONT_USE_USER32_DLL /* Use static binding to "user32.dll". */ @@ -1527,20 +1522,6 @@ GC_API void GC_CALL GC_set_abort_func(GC_abort_func fn) } #endif /* !SMALL_CONFIG */ -STATIC GC_exit_func exit_fn = NULL; - -void GC_exit(int status) -{ - if (exit_fn) exit_fn(status); - (void) exit(status); -} - -GC_API void GC_CALL GC_set_exit_func(GC_exit_func fn) -{ - exit_fn = fn; -} - - GC_API void GC_CALL GC_enable(void) { DCL_LOCK_STATE;