diff options
Diffstat (limited to 'gl/m4/threadlib.m4')
-rw-r--r-- | gl/m4/threadlib.m4 | 63 |
1 files changed, 42 insertions, 21 deletions
diff --git a/gl/m4/threadlib.m4 b/gl/m4/threadlib.m4 index b536b04..f5e8147 100644 --- a/gl/m4/threadlib.m4 +++ b/gl/m4/threadlib.m4 | |||
@@ -1,5 +1,6 @@ | |||
1 | # threadlib.m4 serial 32a | 1 | # threadlib.m4 |
2 | dnl Copyright (C) 2005-2023 Free Software Foundation, Inc. | 2 | # serial 42 |
3 | dnl Copyright (C) 2005-2024 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | 4 | dnl This file is free software; the Free Software Foundation |
4 | dnl gives unlimited permission to copy and/or distribute it, | 5 | dnl gives unlimited permission to copy and/or distribute it, |
5 | dnl with or without modifications, as long as this notice is preserved. | 6 | dnl with or without modifications, as long as this notice is preserved. |
@@ -85,10 +86,11 @@ AC_DEFUN([gl_WEAK_SYMBOLS], | |||
85 | AC_CACHE_CHECK([whether imported symbols can be declared weak], | 86 | AC_CACHE_CHECK([whether imported symbols can be declared weak], |
86 | [gl_cv_have_weak], | 87 | [gl_cv_have_weak], |
87 | [case "$host_os" in | 88 | [case "$host_os" in |
88 | cygwin*) | 89 | cygwin* | mingw* | windows*) |
89 | dnl On Cygwin 3.2.0 with gcc 10.2, the test below would succeed, but | 90 | dnl On Cygwin 3.2.0 with gcc 10.2, and likewise on mingw 10.0.0 with |
90 | dnl programs that use pthread_in_use() with weak symbol references | 91 | dnl gcc 11.3, the test below would succeed, but programs that use |
91 | dnl crash miserably at runtime. | 92 | dnl pthread_in_use() with weak symbol references crash miserably at |
93 | dnl runtime. | ||
92 | gl_cv_have_weak="guessing no" | 94 | gl_cv_have_weak="guessing no" |
93 | ;; | 95 | ;; |
94 | *) | 96 | *) |
@@ -174,7 +176,7 @@ dnl Sets the variable LIBPMULTITHREAD, for programs that really need | |||
174 | dnl multithread functionality. The difference between LIBPTHREAD and | 176 | dnl multithread functionality. The difference between LIBPTHREAD and |
175 | dnl LIBPMULTITHREAD is that on platforms supporting weak symbols, typically | 177 | dnl LIBPMULTITHREAD is that on platforms supporting weak symbols, typically |
176 | dnl LIBPTHREAD is empty whereas LIBPMULTITHREAD is not. | 178 | dnl LIBPTHREAD is empty whereas LIBPMULTITHREAD is not. |
177 | dnl Sets the variable LIB_SCHED_YIELD to the linker options needed to use the | 179 | dnl Sets the variable SCHED_YIELD_LIB to the linker options needed to use the |
178 | dnl sched_yield() function. | 180 | dnl sched_yield() function. |
179 | dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for | 181 | dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for |
180 | dnl multithread-safe programs. | 182 | dnl multithread-safe programs. |
@@ -205,7 +207,7 @@ AC_DEFUN([gl_PTHREADLIB_BODY], | |||
205 | # If -pthread works, prefer it to -lpthread, since Ubuntu 14.04 | 207 | # If -pthread works, prefer it to -lpthread, since Ubuntu 14.04 |
206 | # needs -pthread for some reason. See: | 208 | # needs -pthread for some reason. See: |
207 | # https://lists.gnu.org/r/bug-gnulib/2014-09/msg00023.html | 209 | # https://lists.gnu.org/r/bug-gnulib/2014-09/msg00023.html |
208 | save_LIBS=$LIBS | 210 | saved_LIBS="$LIBS" |
209 | for gl_pthread in '' '-pthread'; do | 211 | for gl_pthread in '' '-pthread'; do |
210 | LIBS="$LIBS $gl_pthread" | 212 | LIBS="$LIBS $gl_pthread" |
211 | AC_LINK_IFELSE( | 213 | AC_LINK_IFELSE( |
@@ -219,7 +221,7 @@ AC_DEFUN([gl_PTHREADLIB_BODY], | |||
219 | [gl_pthread_api=yes | 221 | [gl_pthread_api=yes |
220 | LIBPTHREAD=$gl_pthread | 222 | LIBPTHREAD=$gl_pthread |
221 | LIBPMULTITHREAD=$gl_pthread]) | 223 | LIBPMULTITHREAD=$gl_pthread]) |
222 | LIBS=$save_LIBS | 224 | LIBS="$saved_LIBS" |
223 | test $gl_pthread_api = yes && break | 225 | test $gl_pthread_api = yes && break |
224 | done | 226 | done |
225 | echo "$as_me:__oline__: gl_pthread_api=$gl_pthread_api" >&AS_MESSAGE_LOG_FD | 227 | echo "$as_me:__oline__: gl_pthread_api=$gl_pthread_api" >&AS_MESSAGE_LOG_FD |
@@ -268,6 +270,15 @@ changequote([,])dnl | |||
268 | [Define if the pthread_in_use() detection is hard.]) | 270 | [Define if the pthread_in_use() detection is hard.]) |
269 | esac | 271 | esac |
270 | fi | 272 | fi |
273 | ], | ||
274 | [dnl This is needed on FreeBSD 5.2.1. | ||
275 | AC_CHECK_LIB([thr], [pthread_kill], | ||
276 | [if test $gl_pthread_in_glibc = yes; then | ||
277 | LIBPMULTITHREAD= | ||
278 | else | ||
279 | LIBPMULTITHREAD=-lthr | ||
280 | fi | ||
281 | ]) | ||
271 | ]) | 282 | ]) |
272 | elif test $gl_pthread_api != yes; then | 283 | elif test $gl_pthread_api != yes; then |
273 | # Some library is needed. Try libpthread and libc_r. | 284 | # Some library is needed. Try libpthread and libc_r. |
@@ -299,13 +310,16 @@ changequote([,])dnl | |||
299 | [AC_LANG_PROGRAM( | 310 | [AC_LANG_PROGRAM( |
300 | [[#include <sched.h>]], | 311 | [[#include <sched.h>]], |
301 | [[sched_yield ();]])], | 312 | [[sched_yield ();]])], |
302 | [LIB_SCHED_YIELD= | 313 | [SCHED_YIELD_LIB= |
303 | ], | 314 | ], |
304 | [dnl Solaris 7...10 has sched_yield in librt, not in libpthread or libc. | 315 | [dnl Solaris 7...10 has sched_yield in librt, not in libpthread or libc. |
305 | AC_CHECK_LIB([rt], [sched_yield], [LIB_SCHED_YIELD=-lrt], | 316 | AC_CHECK_LIB([rt], [sched_yield], [SCHED_YIELD_LIB=-lrt], |
306 | [dnl Solaris 2.5.1, 2.6 has sched_yield in libposix4, not librt. | 317 | [dnl Solaris 2.5.1, 2.6 has sched_yield in libposix4, not librt. |
307 | AC_CHECK_LIB([posix4], [sched_yield], [LIB_SCHED_YIELD=-lposix4])]) | 318 | AC_CHECK_LIB([posix4], [sched_yield], [SCHED_YIELD_LIB=-lposix4])]) |
308 | ]) | 319 | ]) |
320 | AC_SUBST([SCHED_YIELD_LIB]) | ||
321 | dnl For backward compatibility. | ||
322 | LIB_SCHED_YIELD="$SCHED_YIELD_LIB" | ||
309 | AC_SUBST([LIB_SCHED_YIELD]) | 323 | AC_SUBST([LIB_SCHED_YIELD]) |
310 | 324 | ||
311 | gl_pthreadlib_body_done=done | 325 | gl_pthreadlib_body_done=done |
@@ -340,7 +354,7 @@ AC_DEFUN([gl_STDTHREADLIB_BODY], | |||
340 | AC_CHECK_HEADERS_ONCE([threads.h]) | 354 | AC_CHECK_HEADERS_ONCE([threads.h]) |
341 | 355 | ||
342 | case "$host_os" in | 356 | case "$host_os" in |
343 | mingw*) | 357 | mingw* | windows*) |
344 | LIBSTDTHREAD= | 358 | LIBSTDTHREAD= |
345 | ;; | 359 | ;; |
346 | *) | 360 | *) |
@@ -351,7 +365,7 @@ AC_DEFUN([gl_STDTHREADLIB_BODY], | |||
351 | dnl on libpthread (for the symbol 'pthread_mutexattr_gettype'). | 365 | dnl on libpthread (for the symbol 'pthread_mutexattr_gettype'). |
352 | dnl glibc >= 2.34, AIX >= 7.1, and Solaris >= 11.4 have thrd_create in | 366 | dnl glibc >= 2.34, AIX >= 7.1, and Solaris >= 11.4 have thrd_create in |
353 | dnl libc. | 367 | dnl libc. |
354 | AC_CHECK_FUNCS([thrd_create]) | 368 | gl_CHECK_FUNCS_ANDROID([thrd_create], [[#include <threads.h>]]) |
355 | if test $ac_cv_func_thrd_create = yes; then | 369 | if test $ac_cv_func_thrd_create = yes; then |
356 | LIBSTDTHREAD= | 370 | LIBSTDTHREAD= |
357 | else | 371 | else |
@@ -364,7 +378,7 @@ AC_DEFUN([gl_STDTHREADLIB_BODY], | |||
364 | fi | 378 | fi |
365 | else | 379 | else |
366 | dnl Libraries needed by thrd.c, mtx.c, cnd.c, tss.c. | 380 | dnl Libraries needed by thrd.c, mtx.c, cnd.c, tss.c. |
367 | LIBSTDTHREAD="$LIBPMULTITHREAD $LIB_SCHED_YIELD" | 381 | LIBSTDTHREAD="$LIBPMULTITHREAD $SCHED_YIELD_LIB" |
368 | fi | 382 | fi |
369 | ;; | 383 | ;; |
370 | esac | 384 | esac |
@@ -435,10 +449,12 @@ AC_DEFUN([gl_THREADLIB_EARLY_BODY], | |||
435 | m4_ifdef([gl_THREADLIB_DEFAULT_NO], | 449 | m4_ifdef([gl_THREADLIB_DEFAULT_NO], |
436 | [m4_divert_text([DEFAULTS], [gl_use_threads_default=no])], | 450 | [m4_divert_text([DEFAULTS], [gl_use_threads_default=no])], |
437 | [m4_divert_text([DEFAULTS], [gl_use_threads_default=])]) | 451 | [m4_divert_text([DEFAULTS], [gl_use_threads_default=])]) |
438 | m4_divert_text([DEFAULTS], [gl_use_winpthreads_default=]) | 452 | dnl gl_use_winpthreads_default defaults to 'no', because in mingw 10, like |
453 | dnl in mingw 5, the use of libwinpthread still makes test-pthread-tss crash. | ||
454 | m4_divert_text([DEFAULTS], [gl_use_winpthreads_default=no]) | ||
439 | AC_ARG_ENABLE([threads], | 455 | AC_ARG_ENABLE([threads], |
440 | AS_HELP_STRING([--enable-threads={isoc|posix|isoc+posix|windows}], [specify multithreading API])m4_ifdef([gl_THREADLIB_DEFAULT_NO], [], [ | 456 | AS_HELP_STRING([[--enable-threads={isoc|posix|isoc+posix|windows}]], [specify multithreading API])m4_ifdef([gl_THREADLIB_DEFAULT_NO], [], [ |
441 | AS_HELP_STRING([--disable-threads], [build without multithread safety])]), | 457 | AS_HELP_STRING([[--disable-threads]], [build without multithread safety])]), |
442 | [gl_use_threads=$enableval], | 458 | [gl_use_threads=$enableval], |
443 | [if test -n "$gl_use_threads_default"; then | 459 | [if test -n "$gl_use_threads_default"; then |
444 | gl_use_threads="$gl_use_threads_default" | 460 | gl_use_threads="$gl_use_threads_default" |
@@ -459,7 +475,7 @@ changequote(,)dnl | |||
459 | esac | 475 | esac |
460 | ;; | 476 | ;; |
461 | dnl Obey gl_AVOID_WINPTHREAD on mingw. | 477 | dnl Obey gl_AVOID_WINPTHREAD on mingw. |
462 | mingw*) | 478 | mingw* | windows*) |
463 | case "$gl_use_winpthreads_default" in | 479 | case "$gl_use_winpthreads_default" in |
464 | yes) gl_use_threads=posix ;; | 480 | yes) gl_use_threads=posix ;; |
465 | no) gl_use_threads=windows ;; | 481 | no) gl_use_threads=windows ;; |
@@ -558,7 +574,7 @@ AC_DEFUN([gl_THREADLIB_BODY], | |||
558 | case "$gl_use_threads" in | 574 | case "$gl_use_threads" in |
559 | yes | windows | win32) # The 'win32' is for backward compatibility. | 575 | yes | windows | win32) # The 'win32' is for backward compatibility. |
560 | if { case "$host_os" in | 576 | if { case "$host_os" in |
561 | mingw*) true;; | 577 | mingw* | windows*) true;; |
562 | *) false;; | 578 | *) false;; |
563 | esac | 579 | esac |
564 | }; then | 580 | }; then |
@@ -569,6 +585,10 @@ AC_DEFUN([gl_THREADLIB_BODY], | |||
569 | ;; | 585 | ;; |
570 | esac | 586 | esac |
571 | fi | 587 | fi |
588 | else | ||
589 | dnl "$gl_use_threads" is "no". | ||
590 | AC_DEFINE([AVOID_ANY_THREADS], [1], | ||
591 | [Define if no multithread safety and no multithreading is desired.]) | ||
572 | fi | 592 | fi |
573 | AC_MSG_CHECKING([for multithread API to use]) | 593 | AC_MSG_CHECKING([for multithread API to use]) |
574 | AC_MSG_RESULT([$gl_threads_api]) | 594 | AC_MSG_RESULT([$gl_threads_api]) |
@@ -601,7 +621,8 @@ dnl ------------------- | |||
601 | dnl Sets the gl_THREADLIB default so that on mingw, a dependency to the | 621 | dnl Sets the gl_THREADLIB default so that on mingw, a dependency to the |
602 | dnl libwinpthread DLL (mingw-w64 winpthreads library) is avoided. | 622 | dnl libwinpthread DLL (mingw-w64 winpthreads library) is avoided. |
603 | dnl The user can still override it at installation time, by using the | 623 | dnl The user can still override it at installation time, by using the |
604 | dnl configure option '--enable-threads'. | 624 | dnl configure option '--enable-threads=posix'. |
625 | dnl As of 2023, this is now the default. | ||
605 | 626 | ||
606 | AC_DEFUN([gl_AVOID_WINPTHREAD], [ | 627 | AC_DEFUN([gl_AVOID_WINPTHREAD], [ |
607 | m4_divert_text([INIT_PREPARE], [gl_use_winpthreads_default=no]) | 628 | m4_divert_text([INIT_PREPARE], [gl_use_winpthreads_default=no]) |