From: Bruno Haible Date: Sun, 21 Sep 2025 00:11:03 +0000 (+0200) Subject: pthread-once: Reduce link dependencies. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d941c98dbf2795952acdfb356548c9ec5567aedc;p=thirdparty%2Fgnulib.git pthread-once: Reduce link dependencies. Linking with -lpthread is not needed on musl libc, macOS, NetBSD, Solaris, Cygwin, Haiku, Android. Reported by Michael Osipov and Tijl Coosemans in . * m4/pthread-once.m4 (gl_PTHREAD_ONCE): Require gl_PTHREADLIB. Set PTHREAD_ONCE_LIB. * modules/pthread-once (Link): Link with $(PTHREAD_ONCE_LIB) instead of $(LIBPMULTITHREAD). * modules/pthread-once-tests (Makefile.am): Update accordingly. --- diff --git a/ChangeLog b/ChangeLog index 2009ef2582..3b4dbeb8ae 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2025-09-20 Bruno Haible + + pthread-once: Reduce link dependencies. + Linking with -lpthread is not needed on musl libc, macOS, NetBSD, + Solaris, Cygwin, Haiku, Android. + Reported by Michael Osipov and + Tijl Coosemans in + . + * m4/pthread-once.m4 (gl_PTHREAD_ONCE): Require gl_PTHREADLIB. Set + PTHREAD_ONCE_LIB. + * modules/pthread-once (Link): Link with $(PTHREAD_ONCE_LIB) instead of + $(LIBPMULTITHREAD). + * modules/pthread-once-tests (Makefile.am): Update accordingly. + 2025-09-20 Bruno Haible nl_langinfo: Work around nl_langinfo multithread-safety bug on macOS 26. diff --git a/m4/pthread-once.m4 b/m4/pthread-once.m4 index 97484129ee..6978bcb563 100644 --- a/m4/pthread-once.m4 +++ b/m4/pthread-once.m4 @@ -1,5 +1,5 @@ # pthread-once.m4 -# serial 3 +# serial 4 dnl Copyright (C) 2019-2025 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -10,15 +10,18 @@ AC_DEFUN([gl_PTHREAD_ONCE], [ AC_REQUIRE([gl_PTHREAD_H]) AC_REQUIRE([AC_CANONICAL_HOST]) + AC_REQUIRE([gl_PTHREADLIB]) if { case "$host_os" in mingw* | windows*) true;; *) false;; esac; } \ && test $gl_threads_api = windows; then dnl Choose function names that don't conflict with the mingw-w64 winpthreads dnl library. REPLACE_PTHREAD_ONCE=1 + PTHREAD_ONCE_LIB= else if test $HAVE_PTHREAD_H = 0; then HAVE_PTHREAD_ONCE=0 + PTHREAD_ONCE_LIB= else dnl Work around Cygwin 3.5.3 bug. AC_CACHE_CHECK([whether pthread_once works], @@ -32,6 +35,17 @@ AC_DEFUN([gl_PTHREAD_ONCE], *yes) ;; *) REPLACE_PTHREAD_ONCE=1 ;; esac + dnl Among the platforms where $(LIBPTHREAD) is empty and + dnl $(LIBPMULTITHREAD) is non-empty, namely + dnl musl libc, macOS, FreeBSD, NetBSD, Solaris, Cygwin, Haiku, Android, + dnl $(LIBPMULTITHREAD) is necessary only on FreeBSD. + case "$host_os" in + freebsd* | dragonfly* | midnightbsd*) + PTHREAD_ONCE_LIB="$LIBPMULTITHREAD" ;; + *) + PTHREAD_ONCE_LIB="$LIBPTHREAD" ;; + esac fi fi + AC_SUBST([PTHREAD_ONCE_LIB]) ]) diff --git a/modules/pthread-once b/modules/pthread-once index 3e6ab5f93b..03d102ef48 100644 --- a/modules/pthread-once +++ b/modules/pthread-once @@ -24,7 +24,7 @@ Include: Link: -$(LIBPMULTITHREAD) +$(PTHREAD_ONCE_LIB) License: LGPLv2+ diff --git a/modules/pthread-once-tests b/modules/pthread-once-tests index 8ec7030ab8..b15703a330 100644 --- a/modules/pthread-once-tests +++ b/modules/pthread-once-tests @@ -15,5 +15,5 @@ AC_CHECK_DECLS_ONCE([alarm]) Makefile.am: TESTS += test-pthread-once1 test-pthread-once2 check_PROGRAMS += test-pthread-once1 test-pthread-once2 -test_pthread_once1_LDADD = $(LDADD) @LIBPMULTITHREAD@ +test_pthread_once1_LDADD = $(LDADD) @PTHREAD_ONCE_LIB@ test_pthread_once2_LDADD = $(LDADD) @LIBPMULTITHREAD@ @SCHED_YIELD_LIB@