threads.m4 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. dnl Copyright (c) 1999, 2000 Sascha Schumann. All rights reserved.
  2. dnl
  3. dnl Redistribution and use in source and binary forms, with or without
  4. dnl modification, are permitted provided that the following conditions
  5. dnl are met:
  6. dnl
  7. dnl 1. Redistributions of source code must retain the above copyright
  8. dnl notice, this list of conditions and the following disclaimer.
  9. dnl
  10. dnl 2. Redistributions in binary form must reproduce the above copyright
  11. dnl notice, this list of conditions and the following disclaimer in
  12. dnl the documentation and/or other materials provided with the
  13. dnl distribution.
  14. dnl
  15. dnl THIS SOFTWARE IS PROVIDED BY SASCHA SCHUMANN ``AS IS'' AND ANY
  16. dnl EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. dnl IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  18. dnl PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SASCHA SCHUMANN OR
  19. dnl HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  20. dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  21. dnl NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  22. dnl LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. dnl HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  24. dnl STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25. dnl ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  26. dnl OF THE POSSIBILITY OF SUCH DAMAGE.
  27. dnl
  28. dnl PTHREADS_FLAGS
  29. dnl
  30. dnl Set some magic defines to achieve POSIX threads conformance.
  31. dnl
  32. AC_DEFUN([PTHREADS_FLAGS],[
  33. if test -z "$host_alias" && test -n "$host"; then
  34. host_alias=$host
  35. fi
  36. if test -z "$host_alias"; then
  37. AC_MSG_ERROR(host_alias is not set. Make sure to run config.guess)
  38. fi
  39. case $host_alias in
  40. *solaris*)
  41. PTHREAD_FLAGS="-D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT";;
  42. *freebsd*)
  43. PTHREAD_FLAGS="-D_REENTRANT -D_THREAD_SAFE";;
  44. *linux*)
  45. PTHREAD_FLAGS=-D_REENTRANT;;
  46. *aix*)
  47. PTHREAD_FLAGS=-D_THREAD_SAFE;;
  48. *irix*)
  49. PTHREAD_FLAGS=-D_POSIX_THREAD_SAFE_FUNCTIONS;;
  50. *hpux*)
  51. PTHREAD_FLAGS=-D_REENTRANT;;
  52. *sco*)
  53. PTHREAD_FLAGS=-D_REENTRANT;;
  54. esac
  55. if test -n "$PTHREAD_FLAGS"; then
  56. CPPFLAGS="$CPPFLAGS $PTHREAD_FLAGS"
  57. fi
  58. ])
  59. dnl
  60. dnl PTHREADS_CHECK_COMPILE
  61. dnl
  62. dnl Check whether the current setup can use POSIX threads calls.
  63. dnl
  64. AC_DEFUN([PTHREADS_CHECK_COMPILE], [
  65. AC_LINK_IFELSE([ AC_LANG_SOURCE([
  66. #include <pthread.h>
  67. #include <stddef.h>
  68. void *thread_routine(void *data) {
  69. return data;
  70. }
  71. int main() {
  72. pthread_t thd;
  73. pthread_mutexattr_t mattr;
  74. int data = 1;
  75. pthread_mutexattr_init(&mattr);
  76. return pthread_create(&thd, NULL, thread_routine, &data);
  77. } ]) ], [
  78. pthreads_checked=yes
  79. ], [
  80. pthreads_checked=no
  81. ]
  82. ) ] )
  83. dnl
  84. dnl PTHREADS_CHECK
  85. dnl
  86. dnl Try to find a way to enable POSIX threads.
  87. dnl
  88. dnl Magic flags
  89. dnl -kthread gcc (FreeBSD)
  90. dnl -Kthread UDK cc (UnixWare)
  91. dnl -mt WorkShop cc (Solaris)
  92. dnl -mthreads gcc (AIX)
  93. dnl -pthread gcc (Linux, FreeBSD, NetBSD, OpenBSD)
  94. dnl -pthreads gcc (Solaris)
  95. dnl -qthreaded AIX cc V5
  96. dnl -threads gcc (HP-UX)
  97. dnl
  98. AC_DEFUN([PTHREADS_CHECK],[
  99. AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[
  100. ac_cv_pthreads_cflags=
  101. if test "$pthreads_working" != "yes"; then
  102. for flag in -kthread -pthread -pthreads -mthreads -Kthread -threads -mt -qthreaded; do
  103. ac_save=$CFLAGS
  104. CFLAGS="$CFLAGS $flag"
  105. PTHREADS_CHECK_COMPILE
  106. CFLAGS=$ac_save
  107. if test "$pthreads_checked" = "yes"; then
  108. ac_cv_pthreads_cflags=$flag
  109. break
  110. fi
  111. done
  112. fi
  113. ])
  114. AC_CACHE_CHECK(for pthreads_lib, ac_cv_pthreads_lib,[
  115. ac_cv_pthreads_lib=
  116. if test "$pthreads_working" != "yes"; then
  117. for lib in pthread pthreads c_r; do
  118. ac_save=$LIBS
  119. LIBS="$LIBS -l$lib"
  120. PTHREADS_CHECK_COMPILE
  121. LIBS=$ac_save
  122. if test "$pthreads_checked" = "yes"; then
  123. ac_cv_pthreads_lib=$lib
  124. break
  125. fi
  126. done
  127. fi
  128. ])
  129. if test "x$ac_cv_pthreads_cflags" != "x" -o "x$ac_cv_pthreads_lib" != "x"; then
  130. pthreads_working="yes"
  131. fi
  132. ])