8 # Check how to find out the number of available CPU cores in the system.
9 # This information is used by tuklib_cpucores.c.
11 # Currently this supports sysctl() (BSDs, OS/2) and sysconf() (GNU/Linux,
12 # Solaris, IRIX, Cygwin).
16 # Author: Lasse Collin
18 # This file has been put into the public domain.
19 # You can do whatever you want with this file.
22 AC_DEFUN_ONCE([TUKLIB_CPUCORES], [
23 AC_REQUIRE([TUKLIB_COMMON])
25 # sys/param.h might be needed by sys/sysctl.h.
26 AC_CHECK_HEADERS([sys/param.h])
28 AC_CACHE_CHECK([how to detect the number of available CPU cores],
29 [tuklib_cv_cpucores_method], [
31 # Look for sysctl() solution first, because on OS/2, both sysconf()
32 # and sysctl() pass the tests in this file, but only sysctl()
34 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
35 #include <sys/types.h>
36 #ifdef HAVE_SYS_PARAM_H
37 # include <sys/param.h>
39 #include <sys/sysctl.h>
43 int name[2] = { CTL_HW, HW_NCPU };
45 size_t cpus_size = sizeof(cpus);
46 sysctl(name, 2, &cpus, &cpus_size, NULL, 0);
49 ]])], [tuklib_cv_cpucores_method=sysctl], [
51 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
57 #ifdef _SC_NPROCESSORS_ONLN
58 /* Many systems using sysconf() */
59 i = sysconf(_SC_NPROCESSORS_ONLN);
62 i = sysconf(_SC_NPROC_ONLN);
67 tuklib_cv_cpucores_method=sysconf
69 tuklib_cv_cpucores_method=unknown
71 case $tuklib_cv_cpucores_method in
73 AC_DEFINE([TUKLIB_CPUCORES_SYSCTL], [1],
74 [Define to 1 if the number of available CPU cores
75 can be detected with sysctl().])
78 AC_DEFINE([TUKLIB_CPUCORES_SYSCONF], [1],
79 [Define to 1 if the number of available CPU cores
80 can be detected with sysconf(_SC_NPROCESSORS_ONLN)
81 or sysconf(_SC_NPROC_ONLN).])