Permalink
Browse files

Use improved POSIX threads check from threads.m4

This is shared between some projects (currently Apache 2.0, mhash, mcrypt)
  • Loading branch information...
Sascha Schumann
Sascha Schumann committed Mar 7, 2000
1 parent 4cb71a0 commit 05024cb094dd9349808704579cee9b351e5ce26f
Showing with 137 additions and 21 deletions.
  1. +130 −0 TSRM/threads.m4
  2. +7 −21 TSRM/tsrm.m4
View
@@ -0,0 +1,130 @@
+dnl Copyright (c) 1999, 2000 Sascha Schumann. All rights reserved.
+dnl
+dnl Redistribution and use in source and binary forms, with or without
+dnl modification, are permitted provided that the following conditions
+dnl are met:
+dnl
+dnl 1. Redistributions of source code must retain the above copyright
+dnl notice, this list of conditions and the following disclaimer.
+dnl
+dnl 2. Redistributions in binary form must reproduce the above copyright
+dnl notice, this list of conditions and the following disclaimer in
+dnl the documentation and/or other materials provided with the
+dnl distribution.
+dnl
+dnl THIS SOFTWARE IS PROVIDED BY SASCHA SCHUMANN ``AS IS'' AND ANY
+dnl EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+dnl IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+dnl PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SASCHA SCHUMANN OR
+dnl HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+dnl NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+dnl LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+dnl HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+dnl STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+dnl ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+dnl OF THE POSSIBILITY OF SUCH DAMAGE.
+
+dnl
+dnl PTHREADS_FLAGS
+dnl
+dnl Set some magic defines to achieve POSIX threads conformance
+dnl
+AC_DEFUN(PTHREADS_FLAGS,[
+ if test -z "$host_alias"; then
+ AC_MSG_ERROR(host_alias is not set. Make sure to run config.guess)
+ fi
+ case "$host_alias" in
+ *solaris*)
+ PTHREAD_FLAGS="-D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT";;
+ *freebsd*)
+ PTHREAD_FLAGS="-D_REENTRANT -D_THREAD_SAFE";;
+ *linux*)
+ PTHREAD_FLAGS="-D_REENTRANT";;
+ *aix*)
+ PTHREAD_FLAGS="-D_THREAD_SAFE";;
+ *irix*)
+ PTHREAD_FLAGS="-D_POSIX_THREAD_SAFE_FUNCTIONS";;
+ esac
+
+ if test -n "$PTHREAD_FLAGS"; then
+ CFLAGS="$CFLAS $PTHREAD_FLAGS"
+ fi
+
+])dnl
+dnl
+dnl PTHREADS_CHECK_COMPILE
+dnl
+dnl Check whether the current setup can use POSIX threads calls
+dnl
+AC_DEFUN(PTHREADS_CHECK_COMPILE, [
+AC_TRY_RUN( [
+#include <pthread.h>
+
+void *thread_routine(void *data) {
+ return data;
+}
+
+int main() {
+ pthread_t thd;
+ int data = 1;
+ return pthread_create(&thd, NULL, thread_routine, &data);
+} ], [
+ pthreads_working="yes"
+ ], [
+ pthreads_working="no"
+ ], pthreads_working="no" ) ] )dnl
+dnl
+dnl PTHREADS_CHECK()
+dnl
+dnl Try to find a way to enable POSIX threads
+dnl
+AC_DEFUN(PTHREADS_CHECK,[
+if test -n "$ac_cv_pthreads_lib"; then
+ LIBS="$LIBS -l$ac_cv_pthreads_lib"
+fi
+
+if test -n "$ac_cv_pthreads_cflags"; then
+ CFLAGS="$CFLAGS $ac_cv_pthreads_cflags"
+fi
+
+PTHREADS_CHECK_COMPILE
+
+AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[
+ac_cv_pthreads_cflags=""
+if test "$pthreads_working" != "yes"; then
+ for flag in -pthreads -pthread -mthreads; do
+ ac_save="$CFLAGS"
+ CFLAGS="$CFLAGS $flag"
+ PTHREADS_CHECK_COMPILE
+ if test "$pthreads_working" = "yes"; then
+ ac_cv_pthreads_cflags="$flag"
+ break
+ fi
+ CFLAGS="$ac_save"
+ done
+fi
+])
+
+AC_CACHE_CHECK(for pthreads_lib, ac_cv_pthreads_lib,[
+ac_cv_pthreads_lib=""
+if test "$pthreads_working" != "yes"; then
+ for lib in pthread pthreads c_r; do
+ ac_save="$LIBS"
+ LIBS="$LIBS -l$lib"
+ PTHREADS_CHECK_COMPILE
+ if test "$pthreads_working" = "yes"; then
+ ac_cv_pthreads_lib="$lib"
+ break
+ fi
+ LIBS="$ac_save"
+ done
+fi
+])
+
+if test "$pthreads_working" = "yes"; then
+ threads_result="POSIX Threads found"
+else
+ threads_result="POSIX Threads not found"
+fi
+])dnl
View
@@ -53,27 +53,13 @@ AC_MSG_RESULT(yes - installed in $PTH_PREFIX)
AC_DEFUN(TSRM_CHECK_PTHREADS,[
-old_CFLAGS="$CFLAGS"
-
-if test -n "$GCC"; then
- TSRM_CHECK_GCC_ARG(-pthread, [
- CFLAGS="$CFLAGS -pthread"
- ],[
- TSRM_CHECK_GCC_ARG(-pthreads, [
- CFLAGS="$CFLAGS -pthreads"
- ])])
-fi
-
-AC_CHECK_FUNCS(pthread_kill)
-
-if test "$ac_cv_func_pthread_kill" != "yes"; then
- CFLAGS="$old_CFLAGS"
- AC_CHECK_LIB(pthread, pthread_kill)
- unset ac_cv_func_pthread_kill
- AC_CHECK_FUNCS(pthread_kill)
- if test "$ac_cv_func_pthread_kill" != "yes"; then
- AC_MSG_ERROR(Your system seems to lack POSIX threads.)
- fi
+sinclude(threads.m4)
+sinclude(TSRM/threads.m4)
+
+PTHREADS_CHECK
+
+if test "$pthreads_working" != "yes"; then
+ AC_MSG_ERROR(Your system seems to lack POSIX threads.)
fi
AC_DEFINE(PTHREADS, 1, Whether to use Pthreads)

0 comments on commit 05024cb

Please sign in to comment.