]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
pthread-once: Reduce link dependencies.
authorBruno Haible <bruno@clisp.org>
Sun, 21 Sep 2025 00:11:03 +0000 (02:11 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 21 Sep 2025 00:11:03 +0000 (02:11 +0200)
Linking with -lpthread is not needed on musl libc, macOS, NetBSD,
Solaris, Cygwin, Haiku, Android.

Reported by Michael Osipov <michael.osipov@innomotics.com> and
Tijl Coosemans <tijl@FreeBSD.org> in
<https://lists.gnu.org/archive/html/bug-gettext/2025-09/msg00019.html>.

* 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.

ChangeLog
m4/pthread-once.m4
modules/pthread-once
modules/pthread-once-tests

index 2009ef2582b8bafeb5e9db0d49d5b731a2f7aaed..3b4dbeb8aebb485845a5d7f3861f03291064928e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2025-09-20  Bruno Haible  <bruno@clisp.org>
+
+       pthread-once: Reduce link dependencies.
+       Linking with -lpthread is not needed on musl libc, macOS, NetBSD,
+       Solaris, Cygwin, Haiku, Android.
+       Reported by Michael Osipov <michael.osipov@innomotics.com> and
+       Tijl Coosemans <tijl@FreeBSD.org> in
+       <https://lists.gnu.org/archive/html/bug-gettext/2025-09/msg00019.html>.
+       * 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  <bruno@clisp.org>
 
        nl_langinfo: Work around nl_langinfo multithread-safety bug on macOS 26.
index 97484129ee3fd8048be739ac0ccca8ba72785d59..6978bcb563f3943a2d920796d89b2582e2f62919 100644 (file)
@@ -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])
 ])
index 3e6ab5f93b56838eae6fd5352df1d317a4d02756..03d102ef48342ec63ec93ecf255e82af02c2afed 100644 (file)
@@ -24,7 +24,7 @@ Include:
 <pthread.h>
 
 Link:
-$(LIBPMULTITHREAD)
+$(PTHREAD_ONCE_LIB)
 
 License:
 LGPLv2+
index 8ec7030ab869d2d3fcceaf4c7f1f75c490082456..b15703a330295de5a7cc8b8f33c6ea0063362b23 100644 (file)
@@ -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@