diff options
Diffstat (limited to 'gl/m4/pthread-once.m4')
| -rw-r--r-- | gl/m4/pthread-once.m4 | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/gl/m4/pthread-once.m4 b/gl/m4/pthread-once.m4 new file mode 100644 index 00000000..85549254 --- /dev/null +++ b/gl/m4/pthread-once.m4 | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | # pthread-once.m4 | ||
| 2 | # serial 6 | ||
| 3 | dnl Copyright (C) 2019-2025 Free Software Foundation, Inc. | ||
| 4 | dnl This file is free software; the Free Software Foundation | ||
| 5 | dnl gives unlimited permission to copy and/or distribute it, | ||
| 6 | dnl with or without modifications, as long as this notice is preserved. | ||
| 7 | dnl This file is offered as-is, without any warranty. | ||
| 8 | |||
| 9 | AC_DEFUN([gl_PTHREAD_ONCE], | ||
| 10 | [ | ||
| 11 | AC_REQUIRE([gl_PTHREAD_H]) | ||
| 12 | AC_REQUIRE([AC_CANONICAL_HOST]) | ||
| 13 | AC_REQUIRE([gl_PTHREADLIB]) | ||
| 14 | |||
| 15 | if { case "$host_os" in mingw* | windows*) true;; *) false;; esac; } \ | ||
| 16 | && test $gl_threads_api = windows; then | ||
| 17 | dnl Choose function names that don't conflict with the mingw-w64 winpthreads | ||
| 18 | dnl library. | ||
| 19 | REPLACE_PTHREAD_ONCE=1 | ||
| 20 | PTHREAD_ONCE_LIB= | ||
| 21 | else | ||
| 22 | if test $HAVE_PTHREAD_H = 0; then | ||
| 23 | HAVE_PTHREAD_ONCE=0 | ||
| 24 | PTHREAD_ONCE_LIB= | ||
| 25 | else | ||
| 26 | dnl Work around Cygwin 3.5.3 bug. | ||
| 27 | AC_CACHE_CHECK([whether pthread_once works], | ||
| 28 | [gl_cv_func_pthread_once_works], | ||
| 29 | [case "$host_os" in | ||
| 30 | cygwin*) gl_cv_func_pthread_once_works="guessing no" ;; | ||
| 31 | *) gl_cv_func_pthread_once_works="yes" ;; | ||
| 32 | esac | ||
| 33 | ]) | ||
| 34 | case "$gl_cv_func_pthread_once_works" in | ||
| 35 | *yes) ;; | ||
| 36 | *) REPLACE_PTHREAD_ONCE=1 ;; | ||
| 37 | esac | ||
| 38 | dnl Determine whether linking requires $(LIBPMULTITHREAD) or only | ||
| 39 | dnl $(LIBPTHREAD). | ||
| 40 | if test -z "$LIBPTHREAD" && test -n "$LIBPMULTITHREAD"; then | ||
| 41 | AC_CACHE_CHECK([whether pthread_once can be used without linking with libpthread], | ||
| 42 | [gl_cv_func_pthread_once_no_lib], | ||
| 43 | [AC_RUN_IFELSE( | ||
| 44 | [AC_LANG_PROGRAM( | ||
| 45 | [[#include <pthread.h> | ||
| 46 | static pthread_once_t a_once = PTHREAD_ONCE_INIT; | ||
| 47 | static int a; | ||
| 48 | static void a_init (void) { a = 8647; } | ||
| 49 | ]], | ||
| 50 | [[if (pthread_once (&a_once, a_init)) return 1; | ||
| 51 | if (a != 8647) return 2; | ||
| 52 | return 0; | ||
| 53 | ]])], | ||
| 54 | [gl_cv_func_pthread_once_no_lib=yes], | ||
| 55 | [gl_cv_func_pthread_once_no_lib=no], | ||
| 56 | [case "$host_os" in | ||
| 57 | # Guess no on glibc. | ||
| 58 | *-gnu* | gnu*) | ||
| 59 | gl_cv_func_pthread_once_no_lib="guessing no" ;; | ||
| 60 | # Guess no on FreeBSD. | ||
| 61 | freebsd* | dragonfly* | midnightbsd*) | ||
| 62 | gl_cv_func_pthread_once_no_lib="guessing no" ;; | ||
| 63 | # Guess yes otherwise. | ||
| 64 | *) | ||
| 65 | gl_cv_func_pthread_once_no_lib="guessing yes" ;; | ||
| 66 | esac | ||
| 67 | ]) | ||
| 68 | ]) | ||
| 69 | case "$gl_cv_func_pthread_once_no_lib" in | ||
| 70 | *yes) PTHREAD_ONCE_LIB="$LIBPTHREAD" ;; | ||
| 71 | *) PTHREAD_ONCE_LIB="$LIBPMULTITHREAD" ;; | ||
| 72 | esac | ||
| 73 | dnl Expected result: | ||
| 74 | dnl PTHREAD_ONCE_LIB is $(LIBPMULTITHREAD) on glibc < 2.34, FreeBSD. | ||
| 75 | dnl PTHREAD_ONCE_LIB is $(LIBPTHREAD) in particular on | ||
| 76 | dnl musl libc, macOS, NetBSD, Solaris, Cygwin, Haiku, Android. | ||
| 77 | else | ||
| 78 | PTHREAD_ONCE_LIB="$LIBPTHREAD" | ||
| 79 | fi | ||
| 80 | fi | ||
| 81 | fi | ||
| 82 | AC_SUBST([PTHREAD_ONCE_LIB]) | ||
| 83 | ]) | ||
