From 6ee14edc1e8ef04861bc6b270aa0b5a57252caa6 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Fri, 23 Mar 2018 01:09:40 +0300 Subject: [PATCH] Explicitly unblock GC signals on GC initialization Issue #175 (bdgwc). Note: NO_SIGNALS_UNBLOCK_IN_MAIN macro is to be defined manually to turn off this feature (for a reason). * include/private/gcconfig.h [GC_NO_PTHREAD_SIGMASK] (NO_SIGNALS_UNBLOCK_IN_MAIN): New macro. * pthread_stop_world.c [GC_PTHREADS && !GC_WIN32_THREADS && !GC_DARWIN_THREADS && !SN_TARGET_ORBIS && !SN_TARGET_PSP2 && !NACL && !GC_OPENBSD_UTHREADS && !NO_SIGNALS_UNBLOCK_IN_MAIN] (GC_unblock_gc_signals): Define. * pthread_stop_world.c [GC_PTHREADS && !GC_WIN32_THREADS && !GC_DARWIN_THREADS && !SN_TARGET_ORBIS && !SN_TARGET_PSP2 && !NACL && !GC_OPENBSD_UTHREADS && !NO_SIGNALS_UNBLOCK_IN_MAIN] (GC_stop_init): Call GC_unblock_gc_signals; add comment. --- include/private/gcconfig.h | 4 ++++ pthread_stop_world.c | 7 ++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/include/private/gcconfig.h b/include/private/gcconfig.h index 408318c3..e382fbd6 100644 --- a/include/private/gcconfig.h +++ b/include/private/gcconfig.h @@ -2975,6 +2975,10 @@ EXTERN_C_BEGIN # define GC_EXPLICIT_SIGNALS_UNBLOCK #endif +#if !defined(NO_SIGNALS_UNBLOCK_IN_MAIN) && defined(GC_NO_PTHREAD_SIGMASK) +# define NO_SIGNALS_UNBLOCK_IN_MAIN +#endif + #if !defined(NO_MARKER_SPECIAL_SIGMASK) \ && (defined(NACL) || defined(GC_WIN32_PTHREADS)) /* Either there is no pthread_sigmask(), or GC marker thread cannot */ diff --git a/pthread_stop_world.c b/pthread_stop_world.c index 454eb429..5b5956d3 100644 --- a/pthread_stop_world.c +++ b/pthread_stop_world.c @@ -186,7 +186,8 @@ GC_API int GC_CALL GC_get_thr_restart_signal(void) ? GC_sig_thr_restart : SIG_THR_RESTART; } -#ifdef GC_EXPLICIT_SIGNALS_UNBLOCK +#if defined(GC_EXPLICIT_SIGNALS_UNBLOCK) \ + || !defined(NO_SIGNALS_UNBLOCK_IN_MAIN) /* Some targets (e.g., Solaris) might require this to be called when */ /* doing thread registering from the thread destructor. */ GC_INNER void GC_unblock_gc_signals(void) @@ -1198,6 +1199,10 @@ GC_INNER void GC_stop_init(void) if (GC_retry_signals) { GC_COND_LOG_PRINTF("Will retry suspend signal if necessary\n"); } +# ifndef NO_SIGNALS_UNBLOCK_IN_MAIN + /* Explicitly unblock the signals once before new threads creation. */ + GC_unblock_gc_signals(); +# endif # endif /* !GC_OPENBSD_UTHREADS && !NACL */ } -- 2.40.0