From ee0e1619e50b937de34582acf3b45bf269468fdf Mon Sep 17 00:00:00 2001 From: Jean-Claude Beaudoin Date: Wed, 4 Jul 2012 20:53:57 +0400 Subject: [PATCH] Add thread suspend/resume signals public setters (POSIX threads) * include/gc.h (GC_set_suspend_signal, GC_set_thr_restart_signal): Add public function declaration (to specify non-default signals to suspend/resume threads). * include/gc.h (GC_get_suspend_signal, GC_get_thr_restart_signal): Update comment. * misc.c (GC_set_suspend_signal, GC_set_thr_restart_signal): Add public no-op function (only for Darwin, OpenBSD, Win32 and NaCl). * pthread_stop_world.c (GC_set_suspend_signal, GC_set_thr_restart_signal): Add public setter to alter the default signals used to suspend and resume threads (only if not OpenBSD or NaCl); has no effect if GC is initialized. --- include/gc.h | 17 +++++++++++++---- misc.c | 10 ++++++++++ pthread_stop_world.c | 14 ++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/include/gc.h b/include/gc.h index 39c4293e..98e1aa45 100644 --- a/include/gc.h +++ b/include/gc.h @@ -1142,12 +1142,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 */ - /* to suspend threads on POSIX systems. Return -1 otherwise. */ + /* Suggest the GC to use the specific signal to suspend threads. */ + /* Has no effect after GC_init and on non-POSIX systems. */ + GC_API void GC_CALL GC_set_suspend_signal(int); + + /* Suggest the GC to use the specific signal to resume threads. */ + /* Has no effect after GC_init and on non-POSIX systems. */ + GC_API void GC_CALL GC_set_thr_restart_signal(int); + + /* Return the signal number (constant after initialization) used by */ + /* the GC to suspend threads on POSIX systems. Return -1 otherwise. */ GC_API int GC_CALL GC_get_suspend_signal(void); - /* Return the signal number (constant) used by the garbage collector */ - /* to restart (resume) threads on POSIX systems. Return -1 otherwise. */ + /* Return the signal number (constant after initialization) used by */ + /* the garbage collector to restart (resume) threads on POSIX */ + /* systems. Return -1 otherwise. */ GC_API int GC_CALL GC_get_thr_restart_signal(void); /* Explicitly enable GC_register_my_thread() invocation. */ diff --git a/misc.c b/misc.c index e3c3478c..e5dbdf79 100644 --- a/misc.c +++ b/misc.c @@ -510,6 +510,16 @@ GC_API void GC_CALL GC_get_heap_usage_safe(GC_word *pheap_size, #if defined(GC_DARWIN_THREADS) || defined(GC_OPENBSD_THREADS) \ || defined(GC_WIN32_THREADS) || (defined(NACL) && defined(THREADS)) /* GC does not use signals to suspend and restart threads. */ + GC_API void GC_CALL GC_set_suspend_signal(int sig GC_ATTR_UNUSED) + { + /* empty */ + } + + GC_API void GC_CALL GC_set_thr_restart_signal(int sig GC_ATTR_UNUSED) + { + /* empty */ + } + GC_API int GC_CALL GC_get_suspend_signal(void) { return -1; diff --git a/pthread_stop_world.c b/pthread_stop_world.c index 74500c4b..231ceeee 100644 --- a/pthread_stop_world.c +++ b/pthread_stop_world.c @@ -144,6 +144,20 @@ STATIC volatile AO_t GC_world_is_stopped = FALSE; STATIC int GC_sig_suspend = SIG_SUSPEND; STATIC int GC_sig_thr_restart = SIG_THR_RESTART; +GC_API void GC_CALL GC_set_suspend_signal(int sig) +{ + if (GC_is_initialized) return; + + GC_sig_suspend = sig; +} + +GC_API void GC_CALL GC_set_thr_restart_signal(int sig) +{ + if (GC_is_initialized) return; + + GC_sig_thr_restart = sig; +} + GC_API int GC_CALL GC_get_suspend_signal(void) { return GC_sig_suspend; -- 2.40.0