From: Ryan Bloom Date: Thu, 23 Dec 1999 21:01:31 +0000 (+0000) Subject: First stab at logic to determine which threading library to use. This also X-Git-Tag: 1.3.10~52 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=84f9b5d2c6e246d0b228605a9d4bd65522cf0d42;p=apache First stab at logic to determine which threading library to use. This also gets rid of the hack of always putting -pthread in the CFLAGS variable. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@84363 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/acinclude.m4 b/acinclude.m4 index f45bc2ce1e..57c8bf78b9 100644 --- a/acinclude.m4 +++ b/acinclude.m4 @@ -95,3 +95,46 @@ AC_DEFUN(APACHE_ONCE,[ fi ]) +dnl +dnl APACHE_CHECK_THREADS() +dnl +dnl Determine the best flags for linking against a threading library. +dnl +AC_DEFUN(THREAD_TEST, [ +AC_TRY_RUN( [ +#include + +void *thread_routine(void *data) { + return data; +} + +int main() { + pthread_t thd; + int data = 1; + return pthread_create(&thd, NULL, thread_routine, &data); +} ], [ + THREADS_WORKING="yes" + ], [ + THREADS_WORKING="no" + ], THREADS_WORKING="no" ) ] ) + +define(APACHE_CHECK_THREADS, [dnl + cflags_orig="$CFLAGS" + ldflags_orig="$LDFLAGS" + for test_cflag in $1; do + for test_ldflag in $2; do + CFLAGS="$test_cflag $cflags_orig" + LDFLAGS="$test_ldflag $ldflags_orig" + THREAD_TEST() + if test "$THREADS_WORKING" = "yes"; then + break + fi + done + if test "$THREADS_WORKING" = "yes"; then + threads_result="Updating CFLAGS and LDFLAGS" + break + fi + threads_result="Threads not found" + done +] ) + diff --git a/configure.in b/configure.in index 58205e3aa0..bdf03dd910 100644 --- a/configure.in +++ b/configure.in @@ -73,6 +73,10 @@ AC_TYPE_PID_T dnl ## Check for library functions +AC_MSG_CHECKING([for which threading library to use]) +APACHE_CHECK_THREADS('' -pthread -D_REENTRANT, '' -lpthread -lc_r) +AC_MSG_RESULT("$threads_result") + dnl See Comment #Spoon AC_CHECK_FUNCS( \ diff --git a/server/mpm/config.m4 b/server/mpm/config.m4 index 3af2173aea..7ab84353e0 100644 --- a/server/mpm/config.m4 +++ b/server/mpm/config.m4 @@ -46,8 +46,6 @@ AC_DEFUN(APACHE_MPM_PTHREAD, [ dnl XXX - We should be checking for the proper flags to use on a particular dnl platform. This will cover a couple of them, anyway - CFLAGS="-pthread $CFLAGS" - CXXFLAGS="-pthread $CXXFLAGS" AC_CHECK_HEADER(pthread.h, [ ],[ AC_MSG_ERROR(This MPM requires pthreads. Try --with-mpm=prefork.)