nproc.m4 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # nproc.m4 serial 5
  2. dnl Copyright (C) 2009-2023 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. AC_DEFUN([gl_NPROC],
  7. [
  8. gl_PREREQ_NPROC
  9. ])
  10. # Prerequisites of lib/nproc.c.
  11. AC_DEFUN([gl_PREREQ_NPROC],
  12. [
  13. dnl Persuade glibc <sched.h> to declare CPU_SETSIZE, CPU_ISSET etc.
  14. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  15. AC_CHECK_HEADERS([sys/pstat.h sys/sysmp.h sys/param.h],,,
  16. [AC_INCLUDES_DEFAULT])
  17. dnl <sys/sysctl.h> requires <sys/param.h> on OpenBSD 4.0.
  18. AC_CHECK_HEADERS([sys/sysctl.h],,,
  19. [AC_INCLUDES_DEFAULT
  20. #if HAVE_SYS_PARAM_H
  21. # include <sys/param.h>
  22. #endif
  23. ])
  24. AC_CHECK_FUNCS([sched_getaffinity sched_getaffinity_np \
  25. pstat_getdynamic sysmp sysctl])
  26. dnl Test whether sched_getaffinity has the expected declaration.
  27. dnl glibc 2.3.[0-2]:
  28. dnl int sched_getaffinity (pid_t, unsigned int, unsigned long int *);
  29. dnl glibc 2.3.3:
  30. dnl int sched_getaffinity (pid_t, cpu_set_t *);
  31. dnl glibc >= 2.3.4:
  32. dnl int sched_getaffinity (pid_t, size_t, cpu_set_t *);
  33. if test $ac_cv_func_sched_getaffinity = yes; then
  34. AC_CACHE_CHECK([for glibc compatible sched_getaffinity],
  35. [gl_cv_func_sched_getaffinity3],
  36. [AC_COMPILE_IFELSE(
  37. [AC_LANG_PROGRAM(
  38. [[#include <errno.h>
  39. #include <sched.h>]],
  40. [[sched_getaffinity (0, 0, (cpu_set_t *) 0);]])],
  41. [gl_cv_func_sched_getaffinity3=yes],
  42. [gl_cv_func_sched_getaffinity3=no])
  43. ])
  44. if test $gl_cv_func_sched_getaffinity3 = yes; then
  45. AC_DEFINE([HAVE_SCHED_GETAFFINITY_LIKE_GLIBC], [1],
  46. [Define to 1 if sched_getaffinity has a glibc compatible declaration.])
  47. fi
  48. fi
  49. ])