futex.m4 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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*)
  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. int lk;],
  25. [syscall (SYS_gettid); syscall (SYS_futex, &lk, 0, 0, 0);])],
  26. [save_LIBS="$LIBS"
  27. LIBS="-lpthread $LIBS"
  28. AC_LINK_IFELSE(
  29. [AC_LANG_PROGRAM(
  30. [#ifndef _GNU_SOURCE
  31. #define _GNU_SOURCE 1
  32. #endif
  33. #include <pthread.h>
  34. pthread_t th; void *status;],
  35. [pthread_tryjoin_np (th, &status);])],[enable_linux_futex=yes],
  36. [if test x$cross_compiling = xno; then
  37. if getconf GNU_LIBPTHREAD_VERSION 2>/dev/null \
  38. | LC_ALL=C grep -i NPTL > /dev/null 2>/dev/null; then :; else
  39. AC_MSG_WARN([The kernel might not support futex or gettid syscalls.
  40. If so, please configure with --disable-linux-futex])
  41. fi
  42. fi
  43. enable_linux_futex=yes])
  44. LIBS="$save_LIBS"])
  45. ;;
  46. yes)
  47. AC_LINK_IFELSE(
  48. [AC_LANG_PROGRAM(
  49. [#include <sys/syscall.h>
  50. int lk;],
  51. [syscall (SYS_gettid); syscall (SYS_futex, &lk, 0, 0, 0);])],[],
  52. [AC_MSG_ERROR([SYS_gettid and SYS_futex required for --enable-linux-futex])])
  53. ;;
  54. esac
  55. ;;
  56. *)
  57. enable_linux_futex=no
  58. ;;
  59. esac
  60. if test x$enable_linux_futex = xyes; then
  61. $1
  62. fi
  63. ])