futex.m4 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. dnl ----------------------------------------------------------------------
  2. dnl This whole bit snagged from libgomp.
  3. dnl
  4. dnl GCC_LINUX_FUTEX
  5. dnl (SHELL-CODE_HANDLER)
  6. dnl
  7. AC_DEFUN([GCC_LINUX_FUTEX],[dnl
  8. GCC_ENABLE(linux-futex,default, ,[use the Linux futex system call],
  9. permit yes|no|default)
  10. case "$target" in
  11. *-linux* | *-uclinux*)
  12. case "$enable_linux_futex" in
  13. default)
  14. # If headers don't have gettid/futex syscalls definition, then
  15. # default to no, otherwise there will be compile time failures.
  16. # Otherwise, default to yes. If we don't detect we are
  17. # compiled/linked against NPTL and not cross-compiling, check
  18. # if programs are run by default against NPTL and if not, issue
  19. # a warning.
  20. enable_linux_futex=no
  21. AC_LINK_IFELSE(
  22. [AC_LANG_PROGRAM(
  23. [#include <sys/syscall.h>
  24. #include <unistd.h>
  25. int lk;],
  26. [syscall (SYS_gettid); syscall (SYS_futex, &lk, 0, 0, 0);])],
  27. [save_LIBS="$LIBS"
  28. LIBS="-lpthread $LIBS"
  29. AC_LINK_IFELSE(
  30. [AC_LANG_PROGRAM(
  31. [#ifndef _GNU_SOURCE
  32. #define _GNU_SOURCE 1
  33. #endif
  34. #include <pthread.h>
  35. pthread_t th; void *status;],
  36. [pthread_tryjoin_np (th, &status);])],[enable_linux_futex=yes],
  37. [if test x$cross_compiling = xno; then
  38. if getconf GNU_LIBPTHREAD_VERSION 2>/dev/null \
  39. | LC_ALL=C grep -i NPTL > /dev/null 2>/dev/null; then :; else
  40. AC_MSG_WARN([The kernel might not support futex or gettid syscalls.
  41. If so, please configure with --disable-linux-futex])
  42. fi
  43. fi
  44. enable_linux_futex=yes])
  45. LIBS="$save_LIBS"])
  46. ;;
  47. yes)
  48. AC_LINK_IFELSE(
  49. [AC_LANG_PROGRAM(
  50. [#include <sys/syscall.h>
  51. #include <unistd.h>
  52. int lk;],
  53. [syscall (SYS_gettid); syscall (SYS_futex, &lk, 0, 0, 0);])],[],
  54. [AC_MSG_ERROR([SYS_gettid and SYS_futex required for --enable-linux-futex])])
  55. ;;
  56. esac
  57. ;;
  58. *)
  59. enable_linux_futex=no
  60. ;;
  61. esac
  62. if test x$enable_linux_futex = xyes; then
  63. $1
  64. fi
  65. ])