"Fossies" - the Fresh Open Source Software Archive

Member "apr-1.7.0/build/apr_threads.m4" (22 Mar 2019, 8949 Bytes) of package /linux/www/apr-1.7.0.tar.bz2:


As a special service "Fossies" has tried to format the requested text file into HTML format (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "apr_threads.m4": 1.6.5_vs_1.7.0.

    1 dnl -------------------------------------------------------- -*- autoconf -*-
    2 dnl Licensed to the Apache Software Foundation (ASF) under one or more
    3 dnl contributor license agreements.  See the NOTICE file distributed with
    4 dnl this work for additional information regarding copyright ownership.
    5 dnl The ASF licenses this file to You under the Apache License, Version 2.0
    6 dnl (the "License"); you may not use this file except in compliance with
    7 dnl the License.  You may obtain a copy of the License at
    8 dnl
    9 dnl     http://www.apache.org/licenses/LICENSE-2.0
   10 dnl
   11 dnl Unless required by applicable law or agreed to in writing, software
   12 dnl distributed under the License is distributed on an "AS IS" BASIS,
   13 dnl WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14 dnl See the License for the specific language governing permissions and
   15 dnl limitations under the License.
   16 
   17 dnl -----------------------------------------------------------------
   18 dnl apr_threads.m4: APR's autoconf macros for testing thread support
   19 dnl
   20 
   21 dnl
   22 dnl APR_CHECK_PTHREADS_H([ ACTION-IF-FOUND [, ACTION-IF-NOT-FOUND]])
   23 dnl
   24 dnl gcc issues warnings when parsing AIX 4.3.3's pthread.h
   25 dnl which causes autoconf to incorrectly conclude that
   26 dnl pthreads is not available.
   27 dnl Turn off warnings if we're using gcc.
   28 dnl
   29 AC_DEFUN(APR_CHECK_PTHREADS_H, [
   30   if test "$GCC" = "yes"; then
   31     SAVE_FL="$CPPFLAGS"
   32     CPPFLAGS="$CPPFLAGS -w"
   33     AC_CHECK_HEADERS(pthread.h, [ $1 ] , [ $2 ] )
   34     CPPFLAGS="$SAVE_FL"
   35   else
   36     AC_CHECK_HEADERS(pthread.h, [ $1 ] , [ $2 ] )
   37   fi
   38 ])dnl
   39 
   40 
   41 dnl
   42 dnl APR_CHECK_PTHREAD_GETSPECIFIC_TWO_ARGS
   43 dnl
   44 AC_DEFUN(APR_CHECK_PTHREAD_GETSPECIFIC_TWO_ARGS, [
   45 AC_CACHE_CHECK(whether pthread_getspecific takes two arguments, ac_cv_pthread_getspecific_two_args,[
   46 AC_TRY_COMPILE([
   47 #include <pthread.h>
   48 ],[
   49 pthread_key_t key;
   50 void *tmp;
   51 pthread_getspecific(key,&tmp);
   52 ],[
   53     ac_cv_pthread_getspecific_two_args=yes
   54 ],[
   55     ac_cv_pthread_getspecific_two_args=no
   56 ])
   57 ])
   58 
   59 if test "$ac_cv_pthread_getspecific_two_args" = "yes"; then
   60   AC_DEFINE(PTHREAD_GETSPECIFIC_TAKES_TWO_ARGS, 1, [Define if pthread_getspecific() has two args])
   61 fi
   62 ])dnl
   63 
   64 
   65 dnl
   66 dnl APR_CHECK_PTHREAD_ATTR_GETDETACHSTATE_ONE_ARG
   67 dnl
   68 AC_DEFUN(APR_CHECK_PTHREAD_ATTR_GETDETACHSTATE_ONE_ARG, [
   69 AC_CACHE_CHECK(whether pthread_attr_getdetachstate takes one argument, ac_cv_pthread_attr_getdetachstate_one_arg,[
   70 AC_TRY_COMPILE([
   71 #include <pthread.h>
   72 ],[
   73 pthread_attr_t *attr;
   74 pthread_attr_getdetachstate(attr);
   75 ],[
   76     ac_cv_pthread_attr_getdetachstate_one_arg=yes
   77 ],[
   78     ac_cv_pthread_attr_getdetachstate_one_arg=no
   79 ])
   80 ])
   81 
   82 if test "$ac_cv_pthread_attr_getdetachstate_one_arg" = "yes"; then
   83   AC_DEFINE(PTHREAD_ATTR_GETDETACHSTATE_TAKES_ONE_ARG, 1, [Define if pthread_attr_getdetachstate() has one arg])
   84 fi
   85 ])dnl
   86 
   87 
   88 dnl
   89 dnl APR_PTHREADS_TRY_RUN(actions-if-success)
   90 dnl
   91 dnl Try running a program which uses pthreads, executing the
   92 dnl actions-if-success commands on success.
   93 dnl
   94 AC_DEFUN(APR_PTHREADS_TRY_RUN, [
   95 AC_TRY_RUN( [
   96 #include <pthread.h>
   97 #include <stddef.h>
   98 
   99 void *thread_routine(void *data) {
  100     return data;
  101 }
  102 
  103 int main() {
  104     pthread_t thd;
  105     pthread_mutexattr_t mattr;
  106     pthread_once_t once_init = PTHREAD_ONCE_INIT;
  107     int data = 1;
  108     pthread_mutexattr_init(&mattr);
  109     return pthread_create(&thd, NULL, thread_routine, &data);
  110 } ], [apr_p_t_r=yes], [apr_p_t_r=no], [apr_p_t_r=no])
  111 
  112 if test $apr_p_t_r = yes; then
  113   $1
  114 fi
  115 
  116 ])dnl
  117 
  118 
  119 dnl
  120 dnl APR_PTHREADS_CHECK()
  121 dnl
  122 dnl Try to find a way to enable POSIX threads.  Sets the 
  123 dnl pthreads_working variable to "yes" on success.
  124 dnl
  125 AC_DEFUN([APR_PTHREADS_CHECK], [
  126 
  127 AC_CACHE_CHECK([for CFLAGS needed for pthreads], [apr_cv_pthreads_cflags],
  128 [apr_ptc_cflags=$CFLAGS
  129  for flag in none -kthread -pthread -pthreads -mt -mthreads -Kthread -threads; do 
  130     CFLAGS=$apr_ptc_cflags
  131     test "x$flag" != "xnone" && CFLAGS="$CFLAGS $flag"
  132     APR_PTHREADS_TRY_RUN([
  133       apr_cv_pthreads_cflags="$flag"
  134       break
  135     ])
  136  done
  137  CFLAGS=$apr_ptc_cflags
  138 ])
  139 
  140 if test -n "$apr_cv_pthreads_cflags"; then
  141    pthreads_working=yes
  142    if test "x$apr_cv_pthreads_cflags" != "xnone"; then
  143      APR_ADDTO(CFLAGS,[$apr_cv_pthreads_cflags])
  144    fi
  145 fi
  146 
  147 # The CFLAGS may or may not be sufficient to ensure that libapr
  148 # depends on the pthreads library: some versions of libtool
  149 # drop -pthread when passed on the link line; some versions of
  150 # gcc ignore -pthread when linking a shared object.  So always
  151 # try and add the relevant library to LIBS too.
  152 
  153 AC_CACHE_CHECK([for LIBS needed for pthreads], [apr_cv_pthreads_lib], [
  154   apr_ptc_libs=$LIBS
  155   for lib in -lpthread -lpthreads -lc_r; do
  156     LIBS="$apr_ptc_libs $lib"
  157     APR_PTHREADS_TRY_RUN([
  158       apr_cv_pthreads_lib=$lib
  159       break
  160     ])
  161   done
  162   LIBS=$apr_ptc_libs
  163 ])
  164 
  165 if test -n "$apr_cv_pthreads_lib"; then
  166    pthreads_working=yes
  167    APR_ADDTO(LIBS,[$apr_cv_pthreads_lib])
  168 fi
  169 
  170 if test "$pthreads_working" = "yes"; then
  171   threads_result="POSIX Threads found"
  172 else
  173   threads_result="POSIX Threads not found"
  174 fi
  175 ])dnl
  176 
  177 dnl
  178 dnl APR_PTHREADS_CHECK_SAVE
  179 dnl APR_PTHREADS_CHECK_RESTORE
  180 dnl
  181 dnl Save the global environment variables that might be modified during
  182 dnl the checks for threading support so that they can restored if the
  183 dnl result is not what the caller wanted.
  184 dnl
  185 AC_DEFUN(APR_PTHREADS_CHECK_SAVE, [
  186   apr_pthsv_CFLAGS="$CFLAGS"
  187   apr_pthsv_LIBS="$LIBS"
  188 ])dnl
  189 
  190 AC_DEFUN(APR_PTHREADS_CHECK_RESTORE, [
  191   CFLAGS="$apr_pthsv_CFLAGS"
  192   LIBS="$apr_pthsv_LIBS"
  193 ])dnl
  194 
  195 dnl
  196 dnl APR_CHECK_SIGWAIT_ONE_ARG
  197 dnl
  198 AC_DEFUN([APR_CHECK_SIGWAIT_ONE_ARG], [
  199   AC_CACHE_CHECK(whether sigwait takes one argument,ac_cv_sigwait_one_arg,[
  200   AC_TRY_COMPILE([
  201 #if defined(__NETBSD__) || defined(DARWIN)
  202     /* When using the unproven-pthreads package, we need to pull in this
  203      * header to get a prototype for sigwait().  Else things will fail later
  204      * on.  XXX Should probably be fixed in the unproven-pthreads package.
  205      * Darwin is declaring sigwait() in the wrong place as well.
  206      */
  207 #include <pthread.h>
  208 #endif
  209 #include <signal.h>
  210 ],[
  211   sigset_t set;
  212  
  213   sigwait(&set);
  214 ],[
  215   ac_cv_sigwait_one_arg=yes
  216 ],[
  217   ac_cv_sigwait_one_arg=no
  218 ])])
  219   if test "$ac_cv_sigwait_one_arg" = "yes"; then
  220     AC_DEFINE(SIGWAIT_TAKES_ONE_ARG,1,[ ])
  221   fi
  222 ])
  223 
  224 dnl Check for recursive mutex support (per SUSv3).
  225 AC_DEFUN([APR_CHECK_PTHREAD_RECURSIVE_MUTEX], [
  226   AC_CACHE_CHECK([for recursive mutex support], [apr_cv_mutex_recursive],
  227 [AC_TRY_RUN([#include <sys/types.h>
  228 #include <pthread.h>
  229 #include <stdlib.h>
  230 
  231 int main() {
  232     pthread_mutexattr_t attr;
  233     pthread_mutex_t m;
  234 
  235     exit (pthread_mutexattr_init(&attr) 
  236           || pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)
  237           || pthread_mutex_init(&m, &attr));
  238 }], [apr_cv_mutex_recursive=yes], [apr_cv_mutex_recursive=no], 
  239 [apr_cv_mutex_recursive=no])])
  240 
  241 if test "$apr_cv_mutex_recursive" = "yes"; then
  242    AC_DEFINE([HAVE_PTHREAD_MUTEX_RECURSIVE], 1,
  243              [Define if recursive pthread mutexes are available])
  244 fi
  245 ])
  246 
  247 dnl Check for robust process-shared mutex support
  248 AC_DEFUN([APR_CHECK_PTHREAD_ROBUST_SHARED_MUTEX], [
  249 AC_CACHE_CHECK([for robust cross-process mutex support], 
  250 [apr_cv_mutex_robust_shared],
  251 [AC_TRY_RUN([
  252 #include <sys/types.h>
  253 #include <pthread.h>
  254 #include <stdlib.h>
  255 
  256 int main(int argc, char **argv)
  257 {
  258     pthread_mutex_t mutex;
  259     pthread_mutexattr_t attr;
  260 
  261     if (pthread_mutexattr_init(&attr))
  262         exit(1);
  263     if (pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED))
  264         exit(2);
  265     if (pthread_mutexattr_setrobust(&attr, PTHREAD_MUTEX_ROBUST))
  266         exit(3);
  267     if (pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT))
  268         exit(4);
  269     if (pthread_mutex_init(&mutex, &attr))
  270         exit(5);
  271     if (pthread_mutexattr_destroy(&attr))
  272         exit(6);
  273     if (pthread_mutex_destroy(&mutex))
  274         exit(7);
  275 
  276     exit(0);
  277 }], [apr_cv_mutex_robust_shared=yes], [
  278 AC_TRY_RUN([
  279 #include <sys/types.h>
  280 #include <pthread.h>
  281 #include <stdlib.h>
  282 
  283 int main(int argc, char **argv)
  284 {
  285     pthread_mutex_t mutex;
  286     pthread_mutexattr_t attr;
  287 
  288     if (pthread_mutexattr_init(&attr))
  289         exit(1);
  290     if (pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED))
  291         exit(2);
  292     if (pthread_mutexattr_setrobust_np(&attr, PTHREAD_MUTEX_ROBUST_NP))
  293         exit(3);
  294     if (pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT))
  295         exit(4);
  296     if (pthread_mutex_init(&mutex, &attr))
  297         exit(5);
  298     if (pthread_mutexattr_destroy(&attr))
  299         exit(6);
  300     if (pthread_mutex_destroy(&mutex))
  301         exit(7);
  302 
  303     exit(0);
  304 }], [apr_cv_mutex_robust_shared=np], [apr_cv_mutex_robust_shared=no])
  305 ])])
  306 
  307 if test "$apr_cv_mutex_robust_shared" = "yes"; then
  308    AC_DEFINE([HAVE_PTHREAD_MUTEX_ROBUST], 1,
  309              [Define if cross-process robust mutexes are available])
  310 elif test "$apr_cv_mutex_robust_shared" = "np"; then
  311    AC_DEFINE([HAVE_PTHREAD_MUTEX_ROBUST_NP], 1,
  312              [Define if non-posix/portable cross-process robust mutexes are available])
  313 fi
  314 ])