xref: /PHP-8.2/TSRM/threads.m4 (revision d657d559)
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  case $host_alias in
35  *solaris*)
36    PTHREAD_FLAGS="-D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT";;
37  *freebsd*)
38    PTHREAD_FLAGS="-D_REENTRANT -D_THREAD_SAFE";;
39  *linux*)
40    PTHREAD_FLAGS=-D_REENTRANT;;
41  *aix*)
42    PTHREAD_FLAGS=-D_THREAD_SAFE;;
43  *hpux*)
44    PTHREAD_FLAGS=-D_REENTRANT;;
45  *sco*)
46    PTHREAD_FLAGS=-D_REENTRANT;;
47  esac
48
49  if test -n "$PTHREAD_FLAGS"; then
50    CPPFLAGS="$CPPFLAGS $PTHREAD_FLAGS"
51  fi
52])
53
54dnl
55dnl PTHREADS_CHECK_COMPILE
56dnl
57dnl Check whether the current setup can use POSIX threads calls.
58dnl
59AC_DEFUN([PTHREADS_CHECK_COMPILE], [
60AC_LINK_IFELSE([ AC_LANG_SOURCE([
61#include <pthread.h>
62#include <stddef.h>
63
64void *thread_routine(void *data) {
65    return data;
66}
67
68int main(void) {
69    pthread_t thd;
70    pthread_mutexattr_t mattr;
71    int data = 1;
72    pthread_mutexattr_init(&mattr);
73    return pthread_create(&thd, NULL, thread_routine, &data);
74} ]) ], [
75  pthreads_checked=yes
76  ], [
77  pthreads_checked=no
78  ]
79) ] )
80
81dnl
82dnl PTHREADS_CHECK
83dnl
84dnl Try to find a way to enable POSIX threads.
85dnl
86dnl  Magic flags
87dnl  -kthread          gcc (FreeBSD)
88dnl  -Kthread          UDK cc (UnixWare)
89dnl  -mt               WorkShop cc (Solaris)
90dnl  -mthreads         gcc (AIX)
91dnl  -pthread          gcc (Linux, FreeBSD, NetBSD, OpenBSD)
92dnl  -pthreads         gcc (Solaris)
93dnl  -qthreaded        AIX cc V5
94dnl  -threads          gcc (HP-UX)
95dnl
96AC_DEFUN([PTHREADS_CHECK],[
97AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[
98ac_cv_pthreads_cflags=
99if test "$pthreads_working" != "yes"; then
100  for flag in -kthread -pthread -pthreads -mthreads -Kthread -threads -mt -qthreaded; do
101    ac_save=$CFLAGS
102    CFLAGS="$CFLAGS $flag"
103    PTHREADS_CHECK_COMPILE
104    CFLAGS=$ac_save
105    if test "$pthreads_checked" = "yes"; then
106      ac_cv_pthreads_cflags=$flag
107      break
108    fi
109  done
110fi
111])
112
113AC_CACHE_CHECK(for pthreads_lib, ac_cv_pthreads_lib,[
114ac_cv_pthreads_lib=
115if test "$pthreads_working" != "yes"; then
116 for lib in pthread pthreads c_r; do
117    ac_save=$LIBS
118    LIBS="$LIBS -l$lib"
119    PTHREADS_CHECK_COMPILE
120    LIBS=$ac_save
121    if test "$pthreads_checked" = "yes"; then
122      ac_cv_pthreads_lib=$lib
123      break
124    fi
125  done
126fi
127])
128
129if test "x$ac_cv_pthreads_cflags" != "x" -o "x$ac_cv_pthreads_lib" != "x"; then
130  pthreads_working="yes"
131fi
132])
133