use hw.physicalcpu to get a more accurate CPU count on OS X (hw.ncpu includes hyperthreading cpus)

This commit is contained in:
Paul Davis
2013-05-08 10:47:23 -04:00
parent b08c71af02
commit eb5096bfc7

View File

@@ -40,7 +40,7 @@ hardware_concurrency()
#elif defined(__APPLE__) || defined(__FreeBSD__)
int count;
size_t size=sizeof(count);
return sysctlbyname("hw.ncpu",&count,&size,NULL,0)?0:count;
return sysctlbyname("hw.physicalcpu",&count,&size,NULL,0)?0:count;
#elif defined(HAVE_UNISTD) && defined(_SC_NPROCESSORS_ONLN)
int const count=sysconf(_SC_NPROCESSORS_ONLN);
return (count>0)?count:0;