threads.m4 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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_TRY_RUN( [
  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_working=yes
  81. ], [
  82. pthreads_working=no
  83. ], [
  84. dnl For cross compiling running this test is of no use. NetWare supports pthreads
  85. pthreads_working=no
  86. case $host_alias in
  87. *netware*)
  88. pthreads_working=yes
  89. esac
  90. ]
  91. ) ] )dnl
  92. dnl
  93. dnl PTHREADS_CHECK()
  94. dnl
  95. dnl Try to find a way to enable POSIX threads
  96. dnl
  97. dnl Magic flags
  98. dnl -kthread gcc (FreeBSD)
  99. dnl -Kthread UDK cc (UnixWare)
  100. dnl -mt WorkShop cc (Solaris)
  101. dnl -mthreads gcc (AIX)
  102. dnl -pthread gcc (Linux, FreeBSD, NetBSD, OpenBSD)
  103. dnl -pthreads gcc (Solaris)
  104. dnl -qthreaded AIX cc V5
  105. dnl -threads gcc (HP-UX)
  106. dnl
  107. AC_DEFUN([PTHREADS_CHECK],[
  108. if test "$beos_threads" = "1"; then
  109. pthreads_working="yes"
  110. ac_cv_pthreads_cflags=""
  111. else
  112. save_CFLAGS=$CFLAGS
  113. save_LIBS=$LIBS
  114. PTHREADS_ASSIGN_VARS
  115. PTHREADS_CHECK_COMPILE
  116. LIBS=$save_LIBS
  117. CFLAGS=$save_CFLAGS
  118. AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[
  119. ac_cv_pthreads_cflags=
  120. if test "$pthreads_working" != "yes"; then
  121. for flag in -kthread -pthread -pthreads -mthreads -Kthread -threads -mt -qthreaded; do
  122. ac_save=$CFLAGS
  123. CFLAGS="$CFLAGS $flag"
  124. PTHREADS_CHECK_COMPILE
  125. CFLAGS=$ac_save
  126. if test "$pthreads_working" = "yes"; then
  127. ac_cv_pthreads_cflags=$flag
  128. break
  129. fi
  130. done
  131. fi
  132. fi
  133. ])
  134. AC_CACHE_CHECK(for pthreads_lib, ac_cv_pthreads_lib,[
  135. ac_cv_pthreads_lib=
  136. if test "$pthreads_working" != "yes"; then
  137. for lib in pthread pthreads c_r; do
  138. ac_save=$LIBS
  139. LIBS="$LIBS -l$lib"
  140. PTHREADS_CHECK_COMPILE
  141. LIBS=$ac_save
  142. if test "$pthreads_working" = "yes"; then
  143. ac_cv_pthreads_lib=$lib
  144. break
  145. fi
  146. done
  147. fi
  148. ])
  149. if test "$pthreads_working" = "yes"; then
  150. threads_result="POSIX-Threads found"
  151. else
  152. threads_result="POSIX-Threads not found"
  153. fi
  154. ])dnl
  155. dnl
  156. dnl
  157. AC_DEFUN([PTHREADS_ASSIGN_VARS],[
  158. if test -n "$ac_cv_pthreads_lib"; then
  159. LIBS="$LIBS -l$ac_cv_pthreads_lib"
  160. fi
  161. if test -n "$ac_cv_pthreads_cflags"; then
  162. CFLAGS="$CFLAGS $ac_cv_pthreads_cflags"
  163. fi
  164. ])dnl