From 20ce8b64aeeb47d849eff89fd9c7472833df7179 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 10 Apr 2026 23:11:40 +0200 Subject: [PATCH] sigprocmask: Allow single-thread optimization again. * lib/sigprocmask.c (glwthread_spin_lock, glwthread_spin_unlock): Define to empty if GNULIB_SIGPROCMASK_SINGLE_THREAD is defined. (overrides_mt_lock, overrides_handler_lock): Don't define if GNULIB_SIGPROCMASK_SINGLE_THREAD is defined. * doc/multithread.texi (Multithreading Optimizations): Document GNULIB_SIGPROCMASK_SINGLE_THREAD instead of GNULIB_PTHREAD_SIGMASK_SINGLE_THREAD. --- ChangeLog | 11 +++++++++++ doc/multithread.texi | 7 ++++--- lib/sigprocmask.c | 9 ++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index e89c273e1d..4b627f3ea2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2026-04-10 Bruno Haible + + sigprocmask: Allow single-thread optimization again. + * lib/sigprocmask.c (glwthread_spin_lock, glwthread_spin_unlock): Define + to empty if GNULIB_SIGPROCMASK_SINGLE_THREAD is defined. + (overrides_mt_lock, overrides_handler_lock): Don't define if + GNULIB_SIGPROCMASK_SINGLE_THREAD is defined. + * doc/multithread.texi (Multithreading Optimizations): Document + GNULIB_SIGPROCMASK_SINGLE_THREAD instead of + GNULIB_PTHREAD_SIGMASK_SINGLE_THREAD. + 2026-04-10 Bruno Haible sigprocmask: Fix a signal-handler hang in case of a race condition. diff --git a/doc/multithread.texi b/doc/multithread.texi index d86da6d340..f53f5d6a77 100644 --- a/doc/multithread.texi +++ b/doc/multithread.texi @@ -323,9 +323,10 @@ This macro optimizes the functions @code{mbrtowc}, @code{mbrtoc32}, and You can get this macro defined by including the Gnulib module @code{wchar-single}. @item -You may define the C macro @code{GNULIB_PTHREAD_SIGMASK_SINGLE_THREAD} -if all the programs in your package invoke @code{pthread_sigmask} only -from a single thread. +You may define the C macro @code{GNULIB_SIGPROCMASK_SINGLE_THREAD}, if all the +programs in your package invoke the functions of the @code{sigprocmask} module +(in particular, @code{sigprocmask}, @code{pthread_sigmask}, @code{signal}, and +@code{sigaction}) only from a single thread. @item You may define the C macro @code{GNULIB_EXCLUDE_SINGLE_THREAD}, if all the programs in your package invoke the functions of the @code{exclude} module diff --git a/lib/sigprocmask.c b/lib/sigprocmask.c index 92b774f3b0..25b698d869 100644 --- a/lib/sigprocmask.c +++ b/lib/sigprocmask.c @@ -28,7 +28,12 @@ # include "msvc-inval.h" #endif -#include "windows-spin.h" +#if GNULIB_SIGPROCMASK_SINGLE_THREAD +# define glwthread_spin_lock(lock) +# define glwthread_spin_unlock(lock) +#else +# include "windows-spin.h" +#endif /* We assume that a platform without POSIX signal blocking functions also does not have the POSIX sigaction() function, only the @@ -222,12 +227,14 @@ struct override }; static struct override overrides[NSIG] /* = { { 0, NULL }, ... } */; +#if !GNULIB_SIGPROCMASK_SINGLE_THREAD /* A spin lock that protects overrides against simultaneous use from different threads, outside signal handlers. */ static glwthread_spinlock_t overrides_mt_lock = GLWTHREAD_SPIN_INIT; /* A spin lock that protects overrides against simultaneous use from a signal handler and a pthread_sigmask invocation. */ static glwthread_spinlock_t overrides_handler_lock = GLWTHREAD_SPIN_INIT; +#endif /* Signal handler that overrides an original one. */ static void -- 2.47.3