]> granicus.if.org Git - gc/commitdiff
Replace SIG_SUSPEND macro to a variable in pthread_stop_world
authorIvan Maidanski <ivmai@mail.ru>
Wed, 4 Jul 2012 15:00:41 +0000 (19:00 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 4 Jul 2012 15:00:41 +0000 (19:00 +0400)
* misc.c (GC_get_suspend_signal): Define (as always returning -1) in
this file only if Darwin or Win32 threads.
* os_dep.c (GC_dirty_init): Replace SIG_SUSPEND with the value of
GC_get_suspend_signal() invocation.
* pthread_support.c (pthread_sigmask): Likewise.
* pthread_stop_world.c (GC_sig_suspend): New STATIC variable (only
unless NaCl or OpenBSD) initialized to SIG_SUSPEND.
* pthread_stop_world.c (GC_unblock_gc_signals,
GC_suspend_handler_inner, GC_suspend_all, GC_stop_init): Use
GC_sig_suspend instead of SIG_SUSPEND (only unless NaCl or OpenBSD);
update comment.
* pthread_stop_world.c (GC_get_suspend_signal): Define function (which
returns GC_sig_suspend if available).

misc.c
os_dep.c
pthread_stop_world.c
pthread_support.c

diff --git a/misc.c b/misc.c
index 945297dffafe01e9a65fd4369200ca405cfb9d90..702039784ab60a6367580b033145e5a06b8fad56 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -507,24 +507,17 @@ GC_API void GC_CALL GC_get_heap_usage_safe(GC_word *pheap_size,
   UNLOCK();
 }
 
-
-#ifdef THREADS
+#if defined(GC_DARWIN_THREADS) || defined(GC_WIN32_THREADS)
   GC_API int GC_CALL GC_get_suspend_signal(void)
   {
-#   ifdef SIG_SUSPEND
-      return SIG_SUSPEND;
-#   else
-      return -1;
-#   endif
+    return -1; /* GC does not use signals to suspend threads. */
   }
 
-# if defined(GC_DARWIN_THREADS) || defined(GC_WIN32_THREADS)
-    GC_API int GC_CALL GC_get_thr_restart_signal(void)
-    {
-      return -1; /* GC does not use signals to restart threads. */
-    }
-# endif
-#endif /* THREADS */
+  GC_API int GC_CALL GC_get_thr_restart_signal(void)
+  {
+    return -1; /* GC does not use signals to restart threads. */
+  }
+#endif /* GC_DARWIN_THREADS || GC_WIN32_THREADS */
 
 #if !defined(_MAX_PATH) && (defined(MSWIN32) || defined(MSWINCE) \
                             || defined(CYGWIN32))
index 3dda4c071d02f037696afde9f967330525dbba50..d7d05b9dbdd16bc2aff5af9551a9d8f4e4d77212 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -3313,11 +3313,11 @@ GC_INNER void GC_remove_protection(struct hblk *h, word nblocks,
       act.sa_sigaction = GC_write_fault_handler;
       (void)sigemptyset(&act.sa_mask);
 #     ifdef SIG_SUSPEND
-        /* Arrange to postpone SIG_SUSPEND while we're in a write fault */
+        /* Arrange to postpone the signal while we are in a write fault */
         /* handler.  This effectively makes the handler atomic w.r.t.   */
         /* stopping the world for GC.                                   */
-        (void)sigaddset(&act.sa_mask, SIG_SUSPEND);
-#     endif /* SIG_SUSPEND */
+        (void)sigaddset(&act.sa_mask, GC_get_suspend_signal());
+#     endif
 #   endif
     if (GC_print_stats == VERBOSE)
       GC_log_printf(
index dac56e86e64dfe2cb1d2b4c9047d18886d62b602..316ab4d1f0d5f2993cc1676dde02634b851c169e 100644 (file)
@@ -141,6 +141,7 @@ STATIC volatile AO_t GC_world_is_stopped = FALSE;
 #  endif
 #endif
 
+STATIC int GC_sig_suspend = SIG_SUSPEND;
 STATIC int GC_sig_thr_restart = SIG_THR_RESTART;
 
 #ifdef GC_EXPLICIT_SIGNALS_UNBLOCK
@@ -150,7 +151,7 @@ STATIC int GC_sig_thr_restart = SIG_THR_RESTART;
   {
     sigset_t set;
     sigemptyset(&set);
-    sigaddset(&set, SIG_SUSPEND);
+    sigaddset(&set, GC_sig_suspend);
     sigaddset(&set, GC_sig_thr_restart);
     if (pthread_sigmask(SIG_UNBLOCK, &set, NULL) != 0)
       ABORT("pthread_sigmask failed");
@@ -198,7 +199,7 @@ STATIC void GC_suspend_handler_inner(ptr_t sig_arg,
   IF_CANCEL(int cancel_state;)
   AO_t my_stop_count = AO_load(&GC_stop_count);
 
-  if ((signed_word)sig_arg != SIG_SUSPEND)
+  if ((signed_word)sig_arg != GC_sig_suspend)
     ABORT("Bad signal in suspend_handler");
 
   DISABLE_CANCEL(cancel_state);
@@ -457,9 +458,9 @@ STATIC int GC_suspend_all(void)
                         *(ptr_t *)((char *)p -> id + UTHREAD_SP_OFFSET);
 #           else
 #             ifndef PLATFORM_ANDROID
-                result = pthread_kill(p -> id, SIG_SUSPEND);
+                result = pthread_kill(p -> id, GC_sig_suspend);
 #             else
-                result = android_thread_kill(p -> kernel_id, SIG_SUSPEND);
+                result = android_thread_kill(p -> kernel_id, GC_sig_suspend);
 #             endif
               switch(result) {
                 case ESRCH:
@@ -860,7 +861,7 @@ GC_INNER void GC_stop_init(void)
 #   else
       act.sa_handler = GC_suspend_handler;
 #   endif
-    if (sigaction(SIG_SUSPEND, &act, NULL) != 0) {
+    if (sigaction(GC_sig_suspend, &act, NULL) != 0) {
         ABORT("Cannot set SIG_SUSPEND handler");
     }
 
@@ -891,13 +892,22 @@ GC_INNER void GC_stop_init(void)
 # endif /* !GC_OPENBSD_THREADS && !NACL */
 }
 
-  GC_API int GC_CALL GC_get_thr_restart_signal(void)
-  {
-#   if !defined(GC_OPENBSD_THREADS) && !defined(NACL)
-      return GC_sig_thr_restart;
-#   else
-      return -1;
-#   endif
-  }
+GC_API int GC_CALL GC_get_suspend_signal(void)
+{
+# if !defined(GC_OPENBSD_THREADS) && !defined(NACL)
+    return GC_sig_suspend;
+# else
+    return -1;
+# endif
+}
 
-#endif
+GC_API int GC_CALL GC_get_thr_restart_signal(void)
+{
+# if !defined(GC_OPENBSD_THREADS) && !defined(NACL)
+    return GC_sig_thr_restart;
+# else
+    return -1;
+# endif
+}
+
+#endif /* GC_PTHREADS && !GC_DARWIN_THREADS && !GC_WIN32_THREADS */
index ca455d7655021376c65b92f27e3fffca33129efc..4dad56ff44c9a9bb6746ef8391c3159b77d21d13 100644 (file)
@@ -1144,7 +1144,7 @@ GC_INNER void GC_init_parallel(void)
     INIT_REAL_SYMS();
     if (set != NULL && (how == SIG_BLOCK || how == SIG_SETMASK)) {
         fudged_set = *set;
-        sigdelset(&fudged_set, SIG_SUSPEND);
+        sigdelset(&fudged_set, GC_get_suspend_signal());
         set = &fudged_set;
     }
     return(REAL_FUNC(pthread_sigmask)(how, set, oset));