8787AU_ALIAS ( [ ACX_PTHREAD] , [ AX_PTHREAD ] )
8888AC_DEFUN ( [ AX_PTHREAD ] , [
8989AC_REQUIRE ( [ AC_CANONICAL_HOST ] )
90+ AC_REQUIRE ( [ AC_PROG_CC ] )
9091AC_LANG_PUSH ( [ C] )
9192ax_pthread_ok=no
9293
9394# We used to check for pthread.h first, but this fails if pthread.h
94- # requires special compiler flags (e.g. on True64 or Sequent).
95+ # requires special compiler flags (e.g. on Tru64 or Sequent).
9596# It gets checked for in the link test anyway.
9697
9798# First of all, check if the user has set any of the PTHREAD_LIBS,
@@ -102,8 +103,8 @@ if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
102103 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
103104 save_LIBS="$LIBS"
104105 LIBS="$PTHREAD_LIBS $LIBS"
105- AC_MSG_CHECKING ( [ for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS= $PTHREAD_CFLAGS] )
106- AC_TRY_LINK_FUNC ( [ pthread_join] , [ ax_pthread_ok=yes] )
106+ AC_MSG_CHECKING ( [ for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS ] )
107+ AC_LINK_IFELSE ( [ AC_LANG_CALL ( [ ] , [ pthread_join] ) ] , [ ax_pthread_ok=yes] )
107108 AC_MSG_RESULT ( [ $ax_pthread_ok] )
108109 if test x"$ax_pthread_ok" = xno; then
109110 PTHREAD_LIBS=""
123124# which indicates that we try without any flags at all, and "pthread-config"
124125# which is a program returning the flags for the Pth emulation library.
125126
126- ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
127+ ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mt - mthreads pthread --thread-safe pthread-config"
127128
128129# The ordering *is* (sometimes) important. Some notes on the
129130# individual items follow:
@@ -134,49 +135,76 @@ ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mt
134135# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
135136# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
136137# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
137- # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
138+ # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads), Tru64
138139# -pthreads: Solaris/gcc
139- # -mthreads: Mingw32/gcc, Lynx/gcc
140140# -mt: Sun Workshop C (may only link SunOS threads [ -lthread] , but it
141- # doesn't hurt to check since this sometimes defines pthreads too;
142- # also defines -D_REENTRANT)
143- # ... -mt is also the pthreads flag for HP/aCC
141+ # doesn't hurt to check since this sometimes defines pthreads and
142+ # -D_REENTRANT too), HP C (must be checked before -lpthread, which
143+ # is present but should not be used directly)
144+ # -mthreads: Mingw32/gcc, Lynx/gcc
144145# pthread: Linux, etcetera
145146# --thread-safe: KAI C++
146147# pthread-config: use pthread-config program (for GNU Pth library)
147148
148- case ${host_os} in
149+ case $host_os in
150+
151+ hpux*)
152+
153+ # From the cc(1) man page: "[ -mt] Sets various -D flags to enable
154+ # multi-threading and also sets -lpthread."
155+
156+ ax_pthread_flags="-mt -pthread pthread $ax_pthread_flags"
157+ ;;
158+
159+ openedition*)
160+
161+ # IBM z/OS requires a feature-test macro to be defined in order to
162+ # enable POSIX threads at all, so give the user a hint if this is
163+ # not set. (We don't define these ourselves, as they can affect
164+ # other portions of the system API in unpredictable ways.)
165+
166+ AC_EGREP_CPP ( [ AX_PTHREAD_ZOS_MISSING] ,
167+ [
168+ # if !defined(_OPEN_THREADS) && !defined(_UNIX03_THREADS)
169+ AX_PTHREAD_ZOS_MISSING
170+ # endif
171+ ] ,
172+ [ AC_MSG_WARN ( [ IBM z/OS requires -D_OPEN_THREADS or -D_UNIX03_THREADS to enable pthreads support.] ) ] )
173+ ;;
174+
149175 solaris*)
150176
151- # On Solaris (at least, for some versions), libc contains stubbed
177+ # Newer versions of Solaris require the "-mt -lpthread" pair, and we
178+ # check that first. On some older versions, libc contains stubbed
152179 # (non-functional) versions of the pthreads routines, so link-based
153180 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
154181 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
155182 # a function called by this macro, so we could check for that, but
156- # who knows whether they'll stub that too in a future libc.) So,
157- # we'll just look for -pthreads and -lpthread first:
183+ # who knows whether they'll stub that too in a future libc.) So
184+ # we'll look for -pthreads and -lpthread shortly thereafter.
158185
159- ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags"
160- ;;
161-
162- darwin*)
163- ax_pthread_flags="-pthread $ax_pthread_flags"
186+ ax_pthread_flags="-mt,pthread -pthreads -pthread pthread $ax_pthread_flags"
164187 ;;
165188esac
166189
167- # Clang doesn't consider unrecognized options an error unless we specify
168- # -Werror. We throw in some extra Clang-specific options to ensure that
169- # this doesn't happen for GCC, which also accepts -Werror.
170-
171- AC_MSG_CHECKING ( [ if compiler needs -Werror to reject unknown flags] )
172- save_CFLAGS="$CFLAGS"
173- ax_pthread_extra_flags="-Werror"
174- CFLAGS="$CFLAGS $ax_pthread_extra_flags -Wunknown-warning-option -Wsizeof-array-argument"
175- AC_COMPILE_IFELSE ( [ AC_LANG_PROGRAM ( [ int foo(void);] ,[ foo()] ) ] ,
176- [ AC_MSG_RESULT ( [ yes] ) ] ,
177- [ ax_pthread_extra_flags=
178- AC_MSG_RESULT ( [ no] ) ] )
179- CFLAGS="$save_CFLAGS"
190+ # Older versions of Clang only give a warning instead of an error for an
191+ # unrecognized option, unless we specify -Werror. (We throw in some extra
192+ # Clang warning flags for good measure.)
193+
194+ AC_CACHE_CHECK ( [ if compiler needs certain flags to reject unknown flags] ,
195+ [ ax_cv_PTHREAD_REJECT_UNKNOWN] ,
196+ [ ax_cv_PTHREAD_REJECT_UNKNOWN=unknown
197+ save_CFLAGS="$CFLAGS"
198+ ax_pthread_extra_flags="-Wunknown-warning-option -Wunused-command-line-argument"
199+ CFLAGS="$CFLAGS $ax_pthread_extra_flags -Wfoobaz -foobaz"
200+ AC_COMPILE_IFELSE ( [ AC_LANG_PROGRAM ( [ int foo(void);] ,[ foo()] ) ] ,
201+ [ ax_cv_PTHREAD_REJECT_UNKNOWN="-Werror $ax_pthread_extra_flags"] ,
202+ [ ax_cv_PTHREAD_REJECT_UNKNOWN=no] )
203+ CFLAGS="$save_CFLAGS"
204+ ] )
205+ ax_pthread_extra_flags=
206+ AS_IF ( [ test "x$ax_cv_PTHREAD_REJECT_UNKNOWN" != "xno"] ,
207+ [ ax_pthread_extra_flags="$ax_cv_PTHREAD_REJECT_UNKNOWN"] )
180208
181209if test x"$ax_pthread_ok" = xno; then
182210for flag in $ax_pthread_flags; do
@@ -186,6 +214,12 @@ for flag in $ax_pthread_flags; do
186214 AC_MSG_CHECKING ( [ whether pthreads work without any flags] )
187215 ;;
188216
217+ -mt,pthread)
218+ AC_MSG_CHECKING ( [ whether pthreads work with -mt -lpthread] )
219+ PTHREAD_CFLAGS="-mt"
220+ PTHREAD_LIBS="-lpthread"
221+ ;;
222+
189223 -*)
190224 AC_MSG_CHECKING ( [ whether pthreads work with $flag] )
191225 PTHREAD_CFLAGS="$flag"
@@ -251,46 +285,54 @@ if test "x$ax_pthread_ok" = xyes; then
251285 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
252286
253287 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
254- AC_MSG_CHECKING ( [ for joinable pthread attribute] )
255- attr_name=unknown
256- for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
257- AC_LINK_IFELSE ( [ AC_LANG_PROGRAM ( [ #include <pthread.h>] ,
258- [ int attr = $attr; return attr /* ; */] ) ] ,
259- [ attr_name=$attr; break] ,
260- [ ] )
261- done
262- AC_MSG_RESULT ( [ $attr_name] )
263- if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
264- AC_DEFINE_UNQUOTED ( [ PTHREAD_CREATE_JOINABLE] , [ $attr_name] ,
265- [ Define to necessary symbol if this constant
266- uses a non-standard name on your system.] )
267- fi
268-
269- AC_MSG_CHECKING ( [ if more special flags are required for pthreads] )
270- flag=no
271- case ${host_os} in
272- aix* | freebsd* | darwin*) flag="-D_THREAD_SAFE";;
273- osf* | hpux*) flag="-D_REENTRANT";;
274- solaris*)
275- if test "$GCC" = "yes"; then
276- flag="-D_REENTRANT"
277- else
278- # TODO: What about Clang on Solaris?
279- flag="-mt -D_REENTRANT"
280- fi
281- ;;
282- esac
283- AC_MSG_RESULT ( [ $flag] )
284- if test "x$flag" != xno; then
285- PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
286- fi
288+ AC_CACHE_CHECK ( [ for joinable pthread attribute] ,
289+ [ ax_cv_PTHREAD_JOINABLE_ATTR] ,
290+ [ ax_cv_PTHREAD_JOINABLE_ATTR=unknown
291+ for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
292+ AC_LINK_IFELSE ( [ AC_LANG_PROGRAM ( [ #include <pthread.h>] ,
293+ [ int attr = $attr; return attr /* ; */] ) ] ,
294+ [ ax_cv_PTHREAD_JOINABLE_ATTR=$attr; break] ,
295+ [ ] )
296+ done
297+ ] )
298+ AS_IF ( [ test "$ax_cv_PTHREAD_JOINABLE_ATTR" != unknown && \
299+ test "$ax_cv_PTHREAD_JOINABLE_ATTR" != PTHREAD_CREATE_JOINABLE] ,
300+ [ AC_DEFINE_UNQUOTED ( [ PTHREAD_CREATE_JOINABLE] ,
301+ [ $ax_cv_PTHREAD_JOINABLE_ATTR] ,
302+ [ Define to necessary symbol if this constant
303+ uses a non-standard name on your system.] ) ] )
304+
305+ AC_CACHE_CHECK ( [ if more special flags are required for pthreads] ,
306+ [ ax_cv_PTHREAD_SPECIAL_FLAGS] ,
307+ [ ax_cv_PTHREAD_SPECIAL_FLAGS=no
308+ ax_pthread_special_flags_added=no
309+ AC_EGREP_CPP ( [ AX_PTHREAD_NEED_SPECIAL_FLAG] ,
310+ [
311+ # if !defined(_REENTRANT) && !defined(_THREAD_SAFE)
312+ AX_PTHREAD_NEED_SPECIAL_FLAG
313+ # endif
314+ ] ,
315+ [ case $host_os in
316+ aix* | freebsd*)
317+ ax_cv_PTHREAD_SPECIAL_FLAGS="-D_THREAD_SAFE"
318+ ;;
319+ darwin* | hpux* | osf* | solaris*)
320+ ax_cv_PTHREAD_SPECIAL_FLAGS="-D_REENTRANT"
321+ ;;
322+ esac
323+ ] )
324+ ] )
325+ AS_IF ( [ test "x$ax_cv_PTHREAD_SPECIAL_FLAGS" != "xno" && \
326+ test "x$ax_pthread_special_flags_added" != "xyes"] ,
327+ [ PTHREAD_CFLAGS="$ax_cv_PTHREAD_SPECIAL_FLAGS $PTHREAD_CFLAGS"
328+ ax_pthread_special_flags_added=yes] )
287329
288330 AC_CACHE_CHECK ( [ for PTHREAD_PRIO_INHERIT] ,
289- [ ax_cv_PTHREAD_PRIO_INHERIT] , [
290- AC_LINK_IFELSE ( [ AC_LANG_PROGRAM ( [ [ #include <pthread.h>] ] ,
291- [ [ int i = PTHREAD_PRIO_INHERIT;] ] ) ] ,
292- [ ax_cv_PTHREAD_PRIO_INHERIT=yes] ,
293- [ ax_cv_PTHREAD_PRIO_INHERIT=no] )
331+ [ ax_cv_PTHREAD_PRIO_INHERIT] ,
332+ [ AC_LINK_IFELSE ( [ AC_LANG_PROGRAM ( [ [ #include <pthread.h>] ] ,
333+ [ [ int i = PTHREAD_PRIO_INHERIT;] ] ) ] ,
334+ [ ax_cv_PTHREAD_PRIO_INHERIT=yes] ,
335+ [ ax_cv_PTHREAD_PRIO_INHERIT=no] )
294336 ] )
295337 AS_IF ( [ test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes"] ,
296338 [ AC_DEFINE ( [ HAVE_PTHREAD_PRIO_INHERIT] , [ 1] , [ Have PTHREAD_PRIO_INHERIT.] ) ] )
0 commit comments