blob: 7c44d67786d9fb047422e2b020a8166be7b1d13f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#ifdef __WIN32__
#include <windows.h>
#endif
#ifdef __MACH__
#include <sys/types.h>
#include <sys/sysctl.h>
#endif
#include "til_limits.h"
#include "til_util.h"
#define TIL_SYSFS_CPU "/sys/devices/system/cpu/cpu"
unsigned til_get_ncpus(void)
{
#ifdef __WIN32__
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
return MIN(sysinfo.dwNumberOfProcessors, TIL_MAXCPUS);
#endif
#ifdef __MACH__
int count;
size_t count_len = sizeof(count);
if (sysctlbyname("hw.logicalcpu_max", &count, &count_len, NULL, 0) < 0)
return 1;
return MIN(count, TIL_MAXCPUS);
#else
long n;
n = sysconf(_SC_NPROCESSORS_ONLN);
if (n <= 0)
return 1;
return MIN(n, TIL_MAXCPUS);
#endif
}
|