blob: 0e78976ac31603d4fa5e6414aae700329866ec3d (
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
|
#include "system.h"
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#else
#include <unistd.h>
#include <sys/utsname.h>
#endif
unsigned int available_cpus( void )
{
#ifdef _WIN32
SYSTEM_INFO info;
GetSystemInfo( &info );
return info.dwNumberOfProcessors;
#else
#ifdef _SC_NPROCESSORS_ONLN
long nprocs = sysconf( _SC_NPROCESSORS_ONLN );
if( nprocs < -1 ) {
// assuming one CPU if we can't detect the number of
// CPUs (safe fallback)
return 1;
}
return nprocs;
#else
#error No _SC_NPROCESSORS_ONLN, must port first!
#endif
#endif
}
|