]> granicus.if.org Git - gc/commitdiff
Add thread suspend/resume signals public setters (POSIX threads)
authorJean-Claude Beaudoin <jean.claude.beaudoin@gmail.com>
Wed, 4 Jul 2012 16:53:57 +0000 (20:53 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 4 Jul 2012 16:53:57 +0000 (20:53 +0400)
* 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
misc.c
pthread_stop_world.c

index 39c4293ecb4e2b6de374ee081f2e8afe40b3341d..98e1aa4501aacea58d67f6a19cfb6feacf0060a5 100644 (file)
@@ -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 e3c3478c4be1def838fd100dca7dc56a96b91721..e5dbdf79203878487fc9c92456a28bf044495fed 100644 (file)
--- 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;
index 74500c4b3b4a164cae7a29071205748f68e2fdbb..231ceeee79cd7ef1a5cacd12acfc2328ec382961 100644 (file)
@@ -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;