| 1 | # nproc.m4 serial 4 |
| 2 | dnl Copyright (C) 2009-2013 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 | |
| 7 | AC_DEFUN([gl_NPROC], |
| 8 | [ |
| 9 | gl_PREREQ_NPROC |
| 10 | ]) |
| 11 | |
| 12 | # Prerequisites of lib/nproc.c. |
| 13 | AC_DEFUN([gl_PREREQ_NPROC], |
| 14 | [ |
| 15 | dnl Persuade glibc <sched.h> to declare CPU_SETSIZE, CPU_ISSET etc. |
| 16 | AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) |
| 17 | |
| 18 | AC_CHECK_HEADERS([sys/pstat.h sys/sysmp.h sys/param.h],,, |
| 19 | [AC_INCLUDES_DEFAULT]) |
| 20 | dnl <sys/sysctl.h> requires <sys/param.h> on OpenBSD 4.0. |
| 21 | AC_CHECK_HEADERS([sys/sysctl.h],,, |
| 22 | [AC_INCLUDES_DEFAULT |
| 23 | #if HAVE_SYS_PARAM_H |
| 24 | # include <sys/param.h> |
| 25 | #endif |
| 26 | ]) |
| 27 | |
| 28 | AC_CHECK_FUNCS([sched_getaffinity sched_getaffinity_np \ |
| 29 | pstat_getdynamic sysmp sysctl]) |
| 30 | |
| 31 | dnl Test whether sched_getaffinity has the expected declaration. |
| 32 | dnl glibc 2.3.[0-2]: |
| 33 | dnl int sched_getaffinity (pid_t, unsigned int, unsigned long int *); |
| 34 | dnl glibc 2.3.3: |
| 35 | dnl int sched_getaffinity (pid_t, cpu_set_t *); |
| 36 | dnl glibc >= 2.3.4: |
| 37 | dnl int sched_getaffinity (pid_t, size_t, cpu_set_t *); |
| 38 | if test $ac_cv_func_sched_getaffinity = yes; then |
| 39 | AC_CACHE_CHECK([for glibc compatible sched_getaffinity], |
| 40 | [gl_cv_func_sched_getaffinity3], |
| 41 | [AC_COMPILE_IFELSE( |
| 42 | [AC_LANG_PROGRAM( |
| 43 | [[#include <sched.h>]], |
| 44 | [[sched_getaffinity (0, 0, (cpu_set_t *) 0);]])], |
| 45 | [gl_cv_func_sched_getaffinity3=yes], |
| 46 | [gl_cv_func_sched_getaffinity3=no]) |
| 47 | ]) |
| 48 | if test $gl_cv_func_sched_getaffinity3 = yes; then |
| 49 | AC_DEFINE([HAVE_SCHED_GETAFFINITY_LIKE_GLIBC], [1], |
| 50 | [Define to 1 if sched_getaffinity has a glibc compatible declaration.]) |
| 51 | fi |
| 52 | fi |
| 53 | ]) |