]> icculus.org git repositories - icculus/xz.git/blob - m4/tuklib_cpucores.m4
Add IRIX-specific code to tuklib_physmem and tuklib_cpucores.
[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, IRIX, 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_CACHE_CHECK([how to detect the number of available CPU cores],
29         [tuklib_cv_cpucores_method], [
30
31 # Look for sysctl() solution first, because on OS/2, both sysconf()
32 # and sysctl() pass the tests in this file, but only sysctl()
33 # actually works.
34 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
35 #include <sys/types.h>
36 #ifdef HAVE_SYS_PARAM_H
37 #       include <sys/param.h>
38 #endif
39 #include <sys/sysctl.h>
40 int
41 main(void)
42 {
43         int name[2] = { CTL_HW, HW_NCPU };
44         int cpus;
45         size_t cpus_size = sizeof(cpus);
46         sysctl(name, 2, &cpus, &cpus_size, NULL, 0);
47         return 0;
48 }
49 ]])], [tuklib_cv_cpucores_method=sysctl], [
50
51 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
52 #include <unistd.h>
53 int
54 main(void)
55 {
56         long i;
57 #ifdef _SC_NPROCESSORS_ONLN
58         /* Many systems using sysconf() */
59         i = sysconf(_SC_NPROCESSORS_ONLN);
60 #else
61         /* IRIX */
62         i = sysconf(_SC_NPROC_ONLN);
63 #endif
64         return 0;
65 }
66 ]])], [
67         tuklib_cv_cpucores_method=sysconf
68 ], [
69         tuklib_cv_cpucores_method=unknown
70 ])])])
71 case $tuklib_cv_cpucores_method in
72         sysctl)
73                 AC_DEFINE([TUKLIB_CPUCORES_SYSCTL], [1],
74                         [Define to 1 if the number of available CPU cores
75                         can be detected with sysctl().])
76                 ;;
77         sysconf)
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).])
82                 ;;
83 esac
84 ])dnl