task.cpp:
- Have CPU core detect on OS X use sysctl() instead of sysconf().
This commit is contained in:
parent
76732a03ed
commit
823d99c73a
|
@ -23,9 +23,9 @@
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#if defined HOST_LINUX || defined HOST_DARWIN
|
#if defined HOST_LINUX
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#elif defined HOST_BSD
|
#elif defined HOST_BSD || defined HOST_DARWIN
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
#endif
|
#endif
|
||||||
#endif // HOST_WINDOWS
|
#endif // HOST_WINDOWS
|
||||||
|
@ -37,11 +37,11 @@ int getOnlineCores (void)
|
||||||
SYSTEM_INFO sysinfo;
|
SYSTEM_INFO sysinfo;
|
||||||
GetSystemInfo(&sysinfo);
|
GetSystemInfo(&sysinfo);
|
||||||
return sysinfo.dwNumberOfProcessors;
|
return sysinfo.dwNumberOfProcessors;
|
||||||
#elif defined HOST_LINUX || defined HOST_DARWIN
|
#elif defined HOST_LINUX
|
||||||
return sysconf(_SC_NPROCESSORS_ONLN);
|
return sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
#elif defined HOST_BSD
|
#elif defined HOST_BSD || defined HOST_DARWIN
|
||||||
int cores;
|
int cores;
|
||||||
const int mib[4] = { CTL_HW, HW_NCPU, 0, 0 };
|
int mib[4] = { CTL_HW, HW_NCPU, 0, 0 };
|
||||||
size_t len = sizeof(cores); //don't make this const, i guess sysctl can't take a const *
|
size_t len = sizeof(cores); //don't make this const, i guess sysctl can't take a const *
|
||||||
sysctl(mib, 2, &cores, &len, NULL, 0);
|
sysctl(mib, 2, &cores, &len, NULL, 0);
|
||||||
return (cores < 1) ? 1 : cores;
|
return (cores < 1) ? 1 : cores;
|
||||||
|
|
Loading…
Reference in New Issue