Paul Eggert wrote: > > GNULIB_PTHREAD_SIGMASK_SINGLE_THREAD is now no longer used. > > Do you feel that the sigprocmask module should have a single-thread > > optimization again? > > It sounds like it needs one, yes, so that gzip needn't ship those two > files and sigprocmask needn't deal with spin locks.
This patch should fulfil your needs. 2026-04-10 Bruno Haible <[email protected]> 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. 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 @@ 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
