xref: /PHP-7.3/TSRM/threads.m4 (revision 3362620b)
1dnl  Copyright (c) 1999, 2000 Sascha Schumann. All rights reserved.
2dnl
3dnl  Redistribution and use in source and binary forms, with or without
4dnl  modification, are permitted provided that the following conditions
5dnl  are met:
6dnl
7dnl  1. Redistributions of source code must retain the above copyright
8dnl     notice, this list of conditions and the following disclaimer.
9dnl
10dnl  2. Redistributions in binary form must reproduce the above copyright
11dnl     notice, this list of conditions and the following disclaimer in
12dnl     the documentation and/or other materials provided with the
13dnl     distribution.
14dnl
15dnl  THIS SOFTWARE IS PROVIDED BY SASCHA SCHUMANN ``AS IS'' AND ANY
16dnl  EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17dnl  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18dnl  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL SASCHA SCHUMANN OR
19dnl  HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20dnl  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21dnl  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22dnl  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23dnl  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24dnl  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25dnl  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
26dnl  OF THE POSSIBILITY OF SUCH DAMAGE.
27
28dnl
29dnl PTHREADS_FLAGS
30dnl
31dnl Set some magic defines to achieve POSIX threads conformance
32dnl
33AC_DEFUN([PTHREADS_FLAGS],[
34  if test -z "$host_alias" && test -n "$host"; then
35    host_alias=$host
36  fi
37  if test -z "$host_alias"; then
38    AC_MSG_ERROR(host_alias is not set. Make sure to run config.guess)
39  fi
40  case $host_alias in
41  *solaris*)
42    PTHREAD_FLAGS="-D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT";;
43  *freebsd*)
44    PTHREAD_FLAGS="-D_REENTRANT -D_THREAD_SAFE";;
45  *linux*)
46    PTHREAD_FLAGS=-D_REENTRANT;;
47  *aix*)
48    PTHREAD_FLAGS=-D_THREAD_SAFE;;
49  *irix*)
50    PTHREAD_FLAGS=-D_POSIX_THREAD_SAFE_FUNCTIONS;;
51  *hpux*)
52    PTHREAD_FLAGS=-D_REENTRANT;;
53  *sco*)
54    PTHREAD_FLAGS=-D_REENTRANT;;
55dnl Solves sigwait() problem, creates problems with u_long etc.
56dnl    PTHREAD_FLAGS="-D_REENTRANT -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=199506 -D_XOPEN_SOURCE_EXTENDED=1";;
57  esac
58
59  if test -n "$PTHREAD_FLAGS"; then
60    CPPFLAGS="$CPPFLAGS $PTHREAD_FLAGS"
61  fi
62])dnl
63dnl
64dnl PTHREADS_CHECK_COMPILE
65dnl
66dnl Check whether the current setup can use POSIX threads calls
67dnl
68AC_DEFUN([PTHREADS_CHECK_COMPILE], [
69AC_LINK_IFELSE([ AC_LANG_SOURCE([
70#include <pthread.h>
71#include <stddef.h>
72
73void *thread_routine(void *data) {
74    return data;
75}
76
77int main() {
78    pthread_t thd;
79    pthread_mutexattr_t mattr;
80    int data = 1;
81    pthread_mutexattr_init(&mattr);
82    return pthread_create(&thd, NULL, thread_routine, &data);
83} ]) ], [
84  pthreads_checked=yes
85  ], [
86  pthreads_checked=no
87  ]
88) ] )dnl
89dnl
90dnl PTHREADS_CHECK()
91dnl
92dnl Try to find a way to enable POSIX threads
93dnl
94dnl  Magic flags
95dnl  -kthread          gcc (FreeBSD)
96dnl  -Kthread          UDK cc (UnixWare)
97dnl  -mt               WorkShop cc (Solaris)
98dnl  -mthreads         gcc (AIX)
99dnl  -pthread          gcc (Linux, FreeBSD, NetBSD, OpenBSD)
100dnl  -pthreads         gcc (Solaris)
101dnl  -qthreaded        AIX cc V5
102dnl  -threads          gcc (HP-UX)
103dnl
104AC_DEFUN([PTHREADS_CHECK],[
105
106save_CFLAGS=$CFLAGS
107save_LIBS=$LIBS
108PTHREADS_ASSIGN_VARS
109PTHREADS_CHECK_COMPILE
110LIBS=$save_LIBS
111CFLAGS=$save_CFLAGS
112
113AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[
114ac_cv_pthreads_cflags=
115if test "$pthreads_working" != "yes"; then
116  for flag in -kthread -pthread -pthreads -mthreads -Kthread -threads -mt -qthreaded; do
117    ac_save=$CFLAGS
118    CFLAGS="$CFLAGS $flag"
119    PTHREADS_CHECK_COMPILE
120    CFLAGS=$ac_save
121    if test "$pthreads_checked" = "yes"; then
122      ac_cv_pthreads_cflags=$flag
123      break
124    fi
125  done
126fi
127])
128
129AC_CACHE_CHECK(for pthreads_lib, ac_cv_pthreads_lib,[
130ac_cv_pthreads_lib=
131if test "$pthreads_working" != "yes"; then
132 for lib in pthread pthreads c_r; do
133    ac_save=$LIBS
134    LIBS="$LIBS -l$lib"
135    PTHREADS_CHECK_COMPILE
136    LIBS=$ac_save
137    if test "$pthreads_checked" = "yes"; then
138      ac_cv_pthreads_lib=$lib
139      break
140    fi
141  done
142fi
143])
144
145if test "x$ac_cv_pthreads_cflags" != "x" -o "x$ac_cv_pthreads_lib" != "x"; then
146  pthreads_working="yes"
147fi
148
149if test "$pthreads_working" = "yes"; then
150  threads_result="POSIX-Threads found"
151else
152  threads_result="POSIX-Threads not found"
153fi
154])dnl
155dnl
156dnl
157AC_DEFUN([PTHREADS_ASSIGN_VARS],[
158if test -n "$ac_cv_pthreads_lib"; then
159  LIBS="$LIBS -l$ac_cv_pthreads_lib"
160fi
161
162if test -n "$ac_cv_pthreads_cflags"; then
163  CFLAGS="$CFLAGS $ac_cv_pthreads_cflags"
164fi
165])dnl
166