xref: /PHP-7.2/TSRM/threads.m4 (revision 902d39a3)
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
106if test "$beos_threads" = "1"; then
107  pthreads_working="yes"
108  ac_cv_pthreads_cflags=""
109else
110  save_CFLAGS=$CFLAGS
111  save_LIBS=$LIBS
112  PTHREADS_ASSIGN_VARS
113  PTHREADS_CHECK_COMPILE
114  LIBS=$save_LIBS
115  CFLAGS=$save_CFLAGS
116
117  AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[
118  ac_cv_pthreads_cflags=
119  if test "$pthreads_working" != "yes"; then
120    for flag in -kthread -pthread -pthreads -mthreads -Kthread -threads -mt -qthreaded; do
121      ac_save=$CFLAGS
122      CFLAGS="$CFLAGS $flag"
123      PTHREADS_CHECK_COMPILE
124      CFLAGS=$ac_save
125      if test "$pthreads_checked" = "yes"; then
126        ac_cv_pthreads_cflags=$flag
127        break
128      fi
129    done
130  fi
131  ])
132
133  AC_CACHE_CHECK(for pthreads_lib, ac_cv_pthreads_lib,[
134  ac_cv_pthreads_lib=
135  if test "$pthreads_working" != "yes"; then
136   for lib in pthread pthreads c_r; do
137      ac_save=$LIBS
138      LIBS="$LIBS -l$lib"
139      PTHREADS_CHECK_COMPILE
140      LIBS=$ac_save
141      if test "$pthreads_checked" = "yes"; then
142        ac_cv_pthreads_lib=$lib
143        break
144      fi
145    done
146  fi
147  ])
148
149  if test "x$ac_cv_pthreads_cflags" != "x" -o "x$ac_cv_pthreads_lib" != "x"; then
150    pthreads_working="yes"
151  fi
152fi
153
154if test "$pthreads_working" = "yes"; then
155  threads_result="POSIX-Threads found"
156else
157  threads_result="POSIX-Threads not found"
158fi
159])dnl
160dnl
161dnl
162AC_DEFUN([PTHREADS_ASSIGN_VARS],[
163if test -n "$ac_cv_pthreads_lib"; then
164  LIBS="$LIBS -l$ac_cv_pthreads_lib"
165fi
166
167if test -n "$ac_cv_pthreads_cflags"; then
168  CFLAGS="$CFLAGS $ac_cv_pthreads_cflags"
169fi
170])dnl
171