version 1.1.1.2, 2012/05/29 09:29:44
|
version 1.1.1.3, 2021/03/17 13:38:46
|
Line 1
|
Line 1
|
# threadlib.m4 serial 8 (gettext-0.18.2) | # threadlib.m4 serial 16 |
dnl Copyright (C) 2005-2011 Free Software Foundation, Inc. | dnl Copyright (C) 2005-2019 Free Software Foundation, Inc. |
dnl This file is free software; the Free Software Foundation |
dnl This file is free software; the Free Software Foundation |
dnl gives unlimited permission to copy and/or distribute it, |
dnl gives unlimited permission to copy and/or distribute it, |
dnl with or without modifications, as long as this notice is preserved. |
dnl with or without modifications, as long as this notice is preserved. |
|
|
dnl From Bruno Haible. |
dnl From Bruno Haible. |
|
|
|
AC_PREREQ([2.60]) |
|
|
dnl gl_THREADLIB |
dnl gl_THREADLIB |
dnl ------------ |
dnl ------------ |
dnl Tests for a multithreading library to be used. |
dnl Tests for a multithreading library to be used. |
Line 15 dnl default is 'no', otherwise it is system dependent.
|
Line 17 dnl default is 'no', otherwise it is system dependent.
|
dnl can change the choice through the options --enable-threads=choice or |
dnl can change the choice through the options --enable-threads=choice or |
dnl --disable-threads. |
dnl --disable-threads. |
dnl Defines at most one of the macros USE_POSIX_THREADS, USE_SOLARIS_THREADS, |
dnl Defines at most one of the macros USE_POSIX_THREADS, USE_SOLARIS_THREADS, |
dnl USE_PTH_THREADS, USE_WIN32_THREADS | dnl USE_PTH_THREADS, USE_WINDOWS_THREADS |
dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use |
dnl Sets the variables LIBTHREAD and LTLIBTHREAD to the linker options for use |
dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with |
dnl in a Makefile (LIBTHREAD for use without libtool, LTLIBTHREAD for use with |
dnl libtool). |
dnl libtool). |
dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for |
dnl Sets the variables LIBMULTITHREAD and LTLIBMULTITHREAD similarly, for |
dnl programs that really need multithread functionality. The difference |
dnl programs that really need multithread functionality. The difference |
dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak |
dnl between LIBTHREAD and LIBMULTITHREAD is that on platforms supporting weak |
dnl symbols, typically LIBTHREAD="" whereas LIBMULTITHREAD="-lpthread". | dnl symbols, typically LIBTHREAD is empty whereas LIBMULTITHREAD is not. |
dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for |
dnl Adds to CPPFLAGS the flag -D_REENTRANT or -D_THREAD_SAFE if needed for |
dnl multithread-safe programs. |
dnl multithread-safe programs. |
|
|
Line 43 AC_DEFUN([gl_THREADLIB_EARLY_BODY],
|
Line 45 AC_DEFUN([gl_THREADLIB_EARLY_BODY],
|
|
|
AC_REQUIRE([AC_CANONICAL_HOST]) |
AC_REQUIRE([AC_CANONICAL_HOST]) |
dnl _GNU_SOURCE is needed for pthread_rwlock_t on glibc systems. |
dnl _GNU_SOURCE is needed for pthread_rwlock_t on glibc systems. |
dnl AC_USE_SYSTEM_EXTENSIONS was introduced in autoconf 2.60 and obsoletes | AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) |
dnl AC_GNU_SOURCE. | |
m4_ifdef([AC_USE_SYSTEM_EXTENSIONS], | |
[AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])], | |
[AC_REQUIRE([AC_GNU_SOURCE])]) | |
dnl Check for multithreading. |
dnl Check for multithreading. |
m4_ifdef([gl_THREADLIB_DEFAULT_NO], |
m4_ifdef([gl_THREADLIB_DEFAULT_NO], |
[m4_divert_text([DEFAULTS], [gl_use_threads_default=no])], |
[m4_divert_text([DEFAULTS], [gl_use_threads_default=no])], |
[m4_divert_text([DEFAULTS], [gl_use_threads_default=])]) |
[m4_divert_text([DEFAULTS], [gl_use_threads_default=])]) |
AC_ARG_ENABLE([threads], |
AC_ARG_ENABLE([threads], |
AC_HELP_STRING([--enable-threads={posix|solaris|pth|win32}], [specify multithreading API])m4_ifdef([gl_THREADLIB_DEFAULT_NO], [], [ | AC_HELP_STRING([--enable-threads={posix|solaris|pth|windows}], [specify multithreading API])m4_ifdef([gl_THREADLIB_DEFAULT_NO], [], [ |
AC_HELP_STRING([--disable-threads], [build without multithread safety])]), |
AC_HELP_STRING([--disable-threads], [build without multithread safety])]), |
[gl_use_threads=$enableval], |
[gl_use_threads=$enableval], |
[if test -n "$gl_use_threads_default"; then |
[if test -n "$gl_use_threads_default"; then |
Line 66 changequote(,)dnl
|
Line 64 changequote(,)dnl
|
dnl child process gets an endless segmentation fault inside execvp(). |
dnl child process gets an endless segmentation fault inside execvp(). |
dnl Disable multithreading by default on Cygwin 1.5.x, because it has |
dnl Disable multithreading by default on Cygwin 1.5.x, because it has |
dnl bugs that lead to endless loops or crashes. See |
dnl bugs that lead to endless loops or crashes. See |
dnl <http://cygwin.com/ml/cygwin/2009-08/msg00283.html>. | dnl <https://cygwin.com/ml/cygwin/2009-08/msg00283.html>. |
osf*) gl_use_threads=no ;; |
osf*) gl_use_threads=no ;; |
cygwin*) |
cygwin*) |
case `uname -r` in |
case `uname -r` in |
Line 148 int main ()
|
Line 146 int main ()
|
[gl_cv_have_weak="guessing no"]) |
[gl_cv_have_weak="guessing no"]) |
]) |
]) |
fi |
fi |
|
dnl But when linking statically, weak symbols don't work. |
|
case " $LDFLAGS " in |
|
*" -static "*) gl_cv_have_weak=no ;; |
|
esac |
]) |
]) |
if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then |
if test "$gl_use_threads" = yes || test "$gl_use_threads" = posix; then |
# On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that |
# On OSF/1, the compiler needs the flag -pthread or -D_REENTRANT so that |
Line 162 int main ()
|
Line 164 int main ()
|
# Test whether both pthread_mutex_lock and pthread_mutexattr_init exist |
# Test whether both pthread_mutex_lock and pthread_mutexattr_init exist |
# in libc. IRIX 6.5 has the first one in both libc and libpthread, but |
# in libc. IRIX 6.5 has the first one in both libc and libpthread, but |
# the second one only in libpthread, and lock.c needs it. |
# the second one only in libpthread, and lock.c needs it. |
AC_LINK_IFELSE( | # |
[AC_LANG_PROGRAM( | # If -pthread works, prefer it to -lpthread, since Ubuntu 14.04 |
[[#include <pthread.h>]], | # needs -pthread for some reason. See: |
[[pthread_mutex_lock((pthread_mutex_t*)0); | # https://lists.gnu.org/r/bug-gnulib/2014-09/msg00023.html |
pthread_mutexattr_init((pthread_mutexattr_t*)0);]])], | save_LIBS=$LIBS |
[gl_have_pthread=yes]) | for gl_pthread in '' '-pthread'; do |
| LIBS="$LIBS $gl_pthread" |
| AC_LINK_IFELSE( |
| [AC_LANG_PROGRAM( |
| [[#include <pthread.h> |
| pthread_mutex_t m; |
| pthread_mutexattr_t ma; |
| ]], |
| [[pthread_mutex_lock (&m); |
| pthread_mutexattr_init (&ma);]])], |
| [gl_have_pthread=yes |
| LIBTHREAD=$gl_pthread LTLIBTHREAD=$gl_pthread |
| LIBMULTITHREAD=$gl_pthread LTLIBMULTITHREAD=$gl_pthread]) |
| LIBS=$save_LIBS |
| test -n "$gl_have_pthread" && break |
| done |
| |
# Test for libpthread by looking for pthread_kill. (Not pthread_self, |
# Test for libpthread by looking for pthread_kill. (Not pthread_self, |
# since it is defined as a macro on OSF/1.) |
# since it is defined as a macro on OSF/1.) |
if test -n "$gl_have_pthread"; then | if test -n "$gl_have_pthread" && test -z "$LIBTHREAD"; then |
# The program links fine without libpthread. But it may actually |
# The program links fine without libpthread. But it may actually |
# need to link with libpthread in order to create multiple threads. |
# need to link with libpthread in order to create multiple threads. |
AC_CHECK_LIB([pthread], [pthread_kill], |
AC_CHECK_LIB([pthread], [pthread_kill], |
Line 179 int main ()
|
Line 197 int main ()
|
# Therefore pthread_in_use() needs to actually try to create a |
# Therefore pthread_in_use() needs to actually try to create a |
# thread: pthread_create from libc will fail, whereas |
# thread: pthread_create from libc will fail, whereas |
# pthread_create will actually create a thread. |
# pthread_create will actually create a thread. |
|
# On Solaris 10 or newer, this test is no longer needed, because |
|
# libc contains the fully functional pthread functions. |
case "$host_os" in |
case "$host_os" in |
solaris* | hpux*) | solaris | solaris2.[1-9] | solaris2.[1-9].* | hpux*) |
AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1], |
AC_DEFINE([PTHREAD_IN_USE_DETECTION_HARD], [1], |
[Define if the pthread_in_use() detection is hard.]) |
[Define if the pthread_in_use() detection is hard.]) |
esac |
esac |
]) |
]) |
else | elif test -z "$gl_have_pthread"; then |
# Some library is needed. Try libpthread and libc_r. |
# Some library is needed. Try libpthread and libc_r. |
AC_CHECK_LIB([pthread], [pthread_kill], |
AC_CHECK_LIB([pthread], [pthread_kill], |
[gl_have_pthread=yes |
[gl_have_pthread=yes |
Line 276 int main ()
|
Line 296 int main ()
|
fi |
fi |
fi |
fi |
if test -z "$gl_have_pthread"; then |
if test -z "$gl_have_pthread"; then |
if test "$gl_use_threads" = yes || test "$gl_use_threads" = win32; then | case "$gl_use_threads" in |
if { case "$host_os" in | yes | windows | win32) # The 'win32' is for backward compatibility. |
mingw*) true;; | if { case "$host_os" in |
*) false;; | mingw*) true;; |
esac | *) false;; |
}; then | esac |
gl_threads_api=win32 | }; then |
AC_DEFINE([USE_WIN32_THREADS], [1], | gl_threads_api=windows |
[Define if the Win32 multithreading API can be used.]) | AC_DEFINE([USE_WINDOWS_THREADS], [1], |
fi | [Define if the native Windows multithreading API can be used.]) |
fi | fi |
| ;; |
| esac |
fi |
fi |
fi |
fi |
AC_MSG_CHECKING([for multithread API to use]) |
AC_MSG_CHECKING([for multithread API to use]) |
Line 317 AC_DEFUN([gl_DISABLE_THREADS], [
|
Line 339 AC_DEFUN([gl_DISABLE_THREADS], [
|
|
|
dnl Survey of platforms: |
dnl Survey of platforms: |
dnl |
dnl |
dnl Platform Available Compiler Supports test-lock | dnl Platform Available Compiler Supports test-lock |
dnl flavours option weak result | dnl flavours option weak result |
dnl --------------- --------- --------- -------- --------- | dnl --------------- --------- --------- -------- --------- |
dnl Linux 2.4/glibc posix -lpthread Y OK | dnl Linux 2.4/glibc posix -lpthread Y OK |
dnl |
dnl |
dnl GNU Hurd/glibc posix | dnl GNU Hurd/glibc posix |
dnl |
dnl |
dnl FreeBSD 5.3 posix -lc_r Y | dnl Ubuntu 14.04 posix -pthread Y OK |
dnl posix -lkse ? Y | |
dnl posix -lpthread ? Y | |
dnl posix -lthr Y | |
dnl |
dnl |
dnl FreeBSD 5.2 posix -lc_r Y | dnl FreeBSD 5.3 posix -lc_r Y |
dnl posix -lkse Y | dnl posix -lkse ? Y |
dnl posix -lthr Y | dnl posix -lpthread ? Y |
| dnl posix -lthr Y |
dnl |
dnl |
dnl FreeBSD 4.0,4.10 posix -lc_r Y OK | dnl FreeBSD 5.2 posix -lc_r Y |
| dnl posix -lkse Y |
| dnl posix -lthr Y |
dnl |
dnl |
dnl NetBSD 1.6 -- | dnl FreeBSD 4.0,4.10 posix -lc_r Y OK |
dnl |
dnl |
dnl OpenBSD 3.4 posix -lpthread Y OK | dnl NetBSD 1.6 -- |
dnl |
dnl |
dnl MacOS X 10.[123] posix -lpthread Y OK | dnl OpenBSD 3.4 posix -lpthread Y OK |
dnl |
dnl |
dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK | dnl Mac OS X 10.[123] posix -lpthread Y OK |
dnl solaris -lthread Y Sol 7,8: 0.0; Sol 9: OK | |
dnl |
dnl |
dnl HP-UX 11 posix -lpthread N (cc) OK | dnl Solaris 7,8,9 posix -lpthread Y Sol 7,8: 0.0; Sol 9: OK |
| dnl solaris -lthread Y Sol 7,8: 0.0; Sol 9: OK |
| dnl |
| dnl HP-UX 11 posix -lpthread N (cc) OK |
dnl Y (gcc) |
dnl Y (gcc) |
dnl |
dnl |
dnl IRIX 6.5 posix -lpthread Y 0.5 | dnl IRIX 6.5 posix -lpthread Y 0.5 |
dnl |
dnl |
dnl AIX 4.3,5.1 posix -lpthread N AIX 4: 0.5; AIX 5: OK | dnl AIX 4.3,5.1 posix -lpthread N AIX 4: 0.5; AIX 5: OK |
dnl |
dnl |
dnl OSF/1 4.0,5.1 posix -pthread (cc) N OK | dnl OSF/1 4.0,5.1 posix -pthread (cc) N OK |
dnl -lpthread (gcc) Y |
dnl -lpthread (gcc) Y |
dnl |
dnl |
dnl Cygwin posix -lpthread Y OK | dnl Cygwin posix -lpthread Y OK |
dnl |
dnl |
dnl Any of the above pth -lpth 0.0 | dnl Any of the above pth -lpth 0.0 |
dnl |
dnl |
dnl Mingw win32 N OK | dnl Mingw windows N OK |
dnl |
dnl |
dnl BeOS 5 -- | dnl BeOS 5 -- |
dnl |
dnl |
dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is |
dnl The test-lock result shows what happens if in test-lock.c EXPLICIT_YIELD is |
dnl turned off: |
dnl turned off: |