task.cpp:

- Have CPU core detect on OS X use sysctl() instead of sysconf().
This commit is contained in:
rogerman 2014-02-21 21:15:25 +00:00
parent 76732a03ed
commit 823d99c73a
1 changed files with 5 additions and 5 deletions

View File

@ -23,9 +23,9 @@
#include <windows.h>
#else
#include <pthread.h>
#if defined HOST_LINUX || defined HOST_DARWIN
#if defined HOST_LINUX
#include <unistd.h>
#elif defined HOST_BSD
#elif defined HOST_BSD || defined HOST_DARWIN
#include <sys/sysctl.h>
#endif
#endif // HOST_WINDOWS
@ -37,11 +37,11 @@ int getOnlineCores (void)
SYSTEM_INFO sysinfo;
GetSystemInfo(&sysinfo);
return sysinfo.dwNumberOfProcessors;
#elif defined HOST_LINUX || defined HOST_DARWIN
#elif defined HOST_LINUX
return sysconf(_SC_NPROCESSORS_ONLN);
#elif defined HOST_BSD
#elif defined HOST_BSD || defined HOST_DARWIN
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 *
sysctl(mib, 2, &cores, &len, NULL, 0);
return (cores < 1) ? 1 : cores;