threads.m4 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. dnl Solves sigwait() problem, creates problems with u_long etc.
  55. dnl PTHREAD_FLAGS="-D_REENTRANT -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=199506 -D_XOPEN_SOURCE_EXTENDED=1";;
  56. esac
  57. if test -n "$PTHREAD_FLAGS"; then
  58. CPPFLAGS="$CPPFLAGS $PTHREAD_FLAGS"
  59. fi
  60. ])dnl
  61. dnl
  62. dnl PTHREADS_CHECK_COMPILE
  63. dnl
  64. dnl Check whether the current setup can use POSIX threads calls
  65. dnl
  66. AC_DEFUN([PTHREADS_CHECK_COMPILE], [
  67. AC_LINK_IFELSE([ AC_LANG_SOURCE([
  68. #include <pthread.h>
  69. #include <stddef.h>
  70. void *thread_routine(void *data) {
  71. return data;
  72. }
  73. int main() {
  74. pthread_t thd;
  75. pthread_mutexattr_t mattr;
  76. int data = 1;
  77. pthread_mutexattr_init(&mattr);
  78. return pthread_create(&thd, NULL, thread_routine, &data);
  79. } ]) ], [
  80. pthreads_checked=yes
  81. ], [
  82. pthreads_checked=no
  83. ]
  84. ) ] )dnl
  85. dnl
  86. dnl PTHREADS_CHECK()
  87. dnl
  88. dnl Try to find a way to enable POSIX threads
  89. dnl
  90. dnl Magic flags
  91. dnl -kthread gcc (FreeBSD)
  92. dnl -Kthread UDK cc (UnixWare)
  93. dnl -mt WorkShop cc (Solaris)
  94. dnl -mthreads gcc (AIX)
  95. dnl -pthread gcc (Linux, FreeBSD, NetBSD, OpenBSD)
  96. dnl -pthreads gcc (Solaris)
  97. dnl -qthreaded AIX cc V5
  98. dnl -threads gcc (HP-UX)
  99. dnl
  100. AC_DEFUN([PTHREADS_CHECK],[
  101. save_CFLAGS=$CFLAGS
  102. save_LIBS=$LIBS
  103. PTHREADS_ASSIGN_VARS
  104. PTHREADS_CHECK_COMPILE
  105. LIBS=$save_LIBS
  106. CFLAGS=$save_CFLAGS
  107. AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[
  108. ac_cv_pthreads_cflags=
  109. if test "$pthreads_working" != "yes"; then
  110. for flag in -kthread -pthread -pthreads -mthreads -Kthread -threads -mt -qthreaded; do
  111. ac_save=$CFLAGS
  112. CFLAGS="$CFLAGS $flag"
  113. PTHREADS_CHECK_COMPILE
  114. CFLAGS=$ac_save
  115. if test "$pthreads_checked" = "yes"; then
  116. ac_cv_pthreads_cflags=$flag
  117. break
  118. fi
  119. done
  120. fi
  121. ])
  122. AC_CACHE_CHECK(for pthreads_lib, ac_cv_pthreads_lib,[
  123. ac_cv_pthreads_lib=
  124. if test "$pthreads_working" != "yes"; then
  125. for lib in pthread pthreads c_r; do
  126. ac_save=$LIBS
  127. LIBS="$LIBS -l$lib"
  128. PTHREADS_CHECK_COMPILE
  129. LIBS=$ac_save
  130. if test "$pthreads_checked" = "yes"; then
  131. ac_cv_pthreads_lib=$lib
  132. break
  133. fi
  134. done
  135. fi
  136. ])
  137. if test "x$ac_cv_pthreads_cflags" != "x" -o "x$ac_cv_pthreads_lib" != "x"; then
  138. pthreads_working="yes"
  139. fi
  140. if test "$pthreads_working" = "yes"; then
  141. threads_result="POSIX-Threads found"
  142. else
  143. threads_result="POSIX-Threads not found"
  144. fi
  145. ])dnl
  146. dnl
  147. dnl
  148. AC_DEFUN([PTHREADS_ASSIGN_VARS],[
  149. if test -n "$ac_cv_pthreads_lib"; then
  150. LIBS="$LIBS -l$ac_cv_pthreads_lib"
  151. fi
  152. if test -n "$ac_cv_pthreads_cflags"; then
  153. CFLAGS="$CFLAGS $ac_cv_pthreads_cflags"
  154. fi
  155. ])dnl