]> icculus.org git repositories - icculus/xz.git/blob - m4/tuklib_cpucores.m4
Fix incorrect use of "restrict".
[icculus/xz.git] / m4 / tuklib_cpucores.m4
1 #
2 # SYNOPSIS
3 #
4 #   TUKLIB_CPUCORES
5 #
6 # DESCRIPTION
7 #
8 #   Check how to find out the number of available CPU cores in the system.
9 #   This information is used by tuklib_cpucores.c.
10 #
11 #   Currently this supports sysctl() (BSDs, OS/2) and sysconf() (GNU/Linux,
12 #   Solaris, Cygwin).
13 #
14 # COPYING
15 #
16 #   Author: Lasse Collin
17 #
18 #   This file has been put into the public domain.
19 #   You can do whatever you want with this file.
20 #
21
22 AC_DEFUN_ONCE([TUKLIB_CPUCORES], [
23 AC_REQUIRE([TUKLIB_COMMON])
24
25 # sys/param.h might be needed by sys/sysctl.h.
26 AC_CHECK_HEADERS([sys/param.h])
27
28 AC_MSG_CHECKING([how to detect the number of available CPU cores])
29
30 # Look for sysctl() solution first, because on OS/2, both sysconf()
31 # and sysctl() pass the tests in this file, but only sysctl()
32 # actually works.
33 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
34 #include <sys/types.h>
35 #ifdef HAVE_SYS_PARAM_H
36 #       include <sys/param.h>
37 #endif
38 #include <sys/sysctl.h>
39 int
40 main(void)
41 {
42         int name[2] = { CTL_HW, HW_NCPU };
43         int cpus;
44         size_t cpus_size = sizeof(cpus);
45         sysctl(name, 2, &cpus, &cpus_size, NULL, 0);
46         return 0;
47 }
48 ]])], [
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])
53 ], [
54
55 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
56 #include <unistd.h>
57 int
58 main(void)
59 {
60         long i;
61         i = sysconf(_SC_NPROCESSORS_ONLN);
62         return 0;
63 }
64 ]])], [
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])
69 ], [
70         AC_MSG_RESULT([unknown])
71 ])])
72 ])dnl