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,
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_MSG_CHECKING([how to detect the number of available CPU cores])
30 # Look for sysctl() solution first, because on OS/2, both sysconf()
31 # and sysctl() pass the tests in this file, but only sysctl()
33 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
34 #include <sys/types.h>
35 #ifdef HAVE_SYS_PARAM_H
36 # include <sys/param.h>
38 #include <sys/sysctl.h>
42 int name[2] = { CTL_HW, HW_NCPU };
44 size_t cpus_size = sizeof(cpus);
45 sysctl(name, 2, &cpus, &cpus_size, NULL, 0);
49 AC_DEFINE([TUKLIB_CPUCORES_SYSCTL], [1],
50 [Define to 1 if the number of available CPU cores can be
51 detected with sysctl().])
52 AC_MSG_RESULT([sysctl])
55 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
61 i = sysconf(_SC_NPROCESSORS_ONLN);
65 AC_DEFINE([TUKLIB_CPUCORES_SYSCONF], [1],
66 [Define to 1 if the number of available CPU cores can be
67 detected with sysconf(_SC_NPROCESSORS_ONLN).])
68 AC_MSG_RESULT([sysconf])
70 AC_MSG_RESULT([unknown])