From d289f02829d202c60f467e6db30ba8258ce8b328 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Wed, 29 Jul 2026 15:19:28 -0700 Subject: [PATCH] localename: add GNULIB_LOCALENAME_SINGLE_THREAD If GNULIB_LOCALENAME_SINGLE_THREAD is defined, omit locks in localename and getlocalename-related functions. Useful for GNU grep; see . * lib/getlocalename_l-unsafe.c, lib/getlocalename_l.c: * lib/localename.c (USE_ISOC_AND_POSIX_THREADS, USE_ISOC_THREADS) (USE_POSIX_THREADS, USE_WINDOWS_THREADS) [GNULIB_LOCALENAME_SINGLE_THREAD]: Undef. --- ChangeLog | 11 +++++++++++ doc/multithread.texi | 7 ++++++- lib/getlocalename_l-unsafe.c | 7 +++++++ lib/getlocalename_l.c | 7 +++++++ lib/glthread/lock.h | 2 ++ lib/localename.c | 7 +++++++ 6 files changed, 40 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index b4df229a0f..2cbc8b47d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2026-07-29 Paul Eggert + + localename: add GNULIB_LOCALENAME_SINGLE_THREAD + If GNULIB_LOCALENAME_SINGLE_THREAD is defined, + omit locks in localename and getlocalename-related functions. + Useful for GNU grep; see . + * lib/getlocalename_l-unsafe.c, lib/getlocalename_l.c: + * lib/localename.c (USE_ISOC_AND_POSIX_THREADS, USE_ISOC_THREADS) + (USE_POSIX_THREADS, USE_WINDOWS_THREADS) + [GNULIB_LOCALENAME_SINGLE_THREAD]: Undef. + 2026-07-29 Bruno Haible tests: Avoid some more runtime errors with Fil-C. diff --git a/doc/multithread.texi b/doc/multithread.texi index bdf579df83..d14c9cb719 100644 --- a/doc/multithread.texi +++ b/doc/multithread.texi @@ -269,7 +269,7 @@ in the Linux kernel, to lock elision -- single-threaded programs can still profit performance-wise from the assertion that they are single-threaded. -Gnulib defines four facilities that help optimizing for the single-threaded +Gnulib defines several facilities that help optimizing for the single-threaded case. @itemize @bullet @@ -344,4 +344,9 @@ and the other functions' Gnulib implementations use Gnulib 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 only from a single thread. +@item +You may define the C macro @code{GNULIB_LOCALENAME_SINGLE_THREAD}, +if all the programs in your package invoke the functions of the +@code{getlocalename_l-simple}, @code{getlocalename_l-unsafe} and +@code{localename} modules only from a single thread. @end itemize diff --git a/lib/getlocalename_l-unsafe.c b/lib/getlocalename_l-unsafe.c index 1d674f219b..150858f91a 100644 --- a/lib/getlocalename_l-unsafe.c +++ b/lib/getlocalename_l-unsafe.c @@ -20,6 +20,13 @@ #include +#if GNULIB_LOCALENAME_SINGLE_THREAD +# undef USE_ISOC_AND_POSIX_THREADS +# undef USE_ISOC_THREADS +# undef USE_POSIX_THREADS +# undef USE_WINDOWS_THREADS +#endif + /* Specification. */ #include "getlocalename_l-unsafe.h" diff --git a/lib/getlocalename_l.c b/lib/getlocalename_l.c index 140916ceb9..989ba2658d 100644 --- a/lib/getlocalename_l.c +++ b/lib/getlocalename_l.c @@ -16,6 +16,13 @@ #include +#if GNULIB_LOCALENAME_SINGLE_THREAD +# undef USE_ISOC_AND_POSIX_THREADS +# undef USE_ISOC_THREADS +# undef USE_POSIX_THREADS +# undef USE_WINDOWS_THREADS +#endif + /* Specification. */ #include diff --git a/lib/glthread/lock.h b/lib/glthread/lock.h index b9fb907ead..8473c4dbed 100644 --- a/lib/glthread/lock.h +++ b/lib/glthread/lock.h @@ -73,6 +73,8 @@ /* This file uses HAVE_THREADS_H, HAVE_PTHREAD_RWLOCK, HAVE_PTHREAD_RWLOCK_RDLOCK_PREFER_WRITER, PTHREAD_RWLOCK_WRITER_NONRECURSIVE_INITIALIZER_NP, + USE_ISOC_THREADS, USE_POSIX_THREADS, USE_ISOC_AND_POSIX_THREADS, + USE_WINDOWS_THREADS, HAVE_PTHREAD_MUTEX_RECURSIVE. */ #if !_GL_CONFIG_H_INCLUDED #error "Please include config.h first." diff --git a/lib/localename.c b/lib/localename.c index aac0f7ce90..f355013171 100644 --- a/lib/localename.c +++ b/lib/localename.c @@ -22,6 +22,13 @@ #include +#if GNULIB_LOCALENAME_SINGLE_THREAD +# undef USE_ISOC_AND_POSIX_THREADS +# undef USE_ISOC_THREADS +# undef USE_POSIX_THREADS +# undef USE_WINDOWS_THREADS +#endif + /* Specification. */ #include "localename.h" -- 2.47.3