]> icculus.org git repositories - icculus/xz.git/blob - m4/lc_cpucores.m4
Fix wrong macro names in lc_cpucores.m4 and cpucores.h.
[icculus/xz.git] / m4 / lc_cpucores.m4
1 dnl ###########################################################################
2 dnl
3 dnl lc_CPUCORES - Check how to find out the number of online CPU cores
4 dnl
5 dnl Check how to find out the number of available CPU cores in the system.
6 dnl sysconf(_SC_NPROCESSORS_ONLN) works on most systems, except that BSDs
7 dnl use sysctl().
8 dnl
9 dnl ###########################################################################
10 dnl
11 dnl Author: Lasse Collin
12 dnl
13 dnl This file has been put into the public domain.
14 dnl You can do whatever you want with this file.
15 dnl
16 dnl ###########################################################################
17 AC_DEFUN([lc_CPUCORES], [
18 AC_MSG_CHECKING([how to detect the number of available CPU cores])
19 AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
20 #include <unistd.h>
21 int
22 main(void)
23 {
24         long i;
25         i = sysconf(_SC_NPROCESSORS_ONLN);
26         return 0;
27 }
28 ]])], [
29         AC_DEFINE([HAVE_CPUCORES_SYSCONF], [1],
30                 [Define to 1 if the number of available CPU cores can be
31                 detected with sysconf(_SC_NPROCESSORS_ONLN).])
32         AC_MSG_RESULT([sysconf])
33 ], [
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, NULL);
47         return 0;
48 }
49 ]])], [
50         AC_DEFINE([HAVE_CPUCORES_SYSCTL], [1],
51                 [Define to 1 if the number of available CPU cores can be
52                 detected with sysctl().])
53         AC_MSG_RESULT([sysctl])
54 ], [
55         AC_MSG_RESULT([unknown])
56 ])])
57 ])dnl lc_CPUCORES