From 05daaeea173b81102e81ceac932a720f9359bf76 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Wed, 4 Jul 2012 19:00:41 +0400 Subject: [PATCH] Replace SIG_SUSPEND macro to a variable in pthread_stop_world * 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 | 21 +++++++-------------- os_dep.c | 6 +++--- pthread_stop_world.c | 38 ++++++++++++++++++++++++-------------- pthread_support.c | 2 +- 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/misc.c b/misc.c index 945297df..70203978 100644 --- 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)) diff --git a/os_dep.c b/os_dep.c index 3dda4c07..d7d05b9d 100644 --- 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( diff --git a/pthread_stop_world.c b/pthread_stop_world.c index dac56e86..316ab4d1 100644 --- a/pthread_stop_world.c +++ b/pthread_stop_world.c @@ -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 */ diff --git a/pthread_support.c b/pthread_support.c index ca455d76..4dad56ff 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -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)); -- 2.50.1