Skip to content
Snippets Groups Projects
Commit a7986e29 authored by dg's avatar dg
Browse files

make cpu count work on osx

git-svn-id: http://svn.net-core.org/repos/t-engine4@2605 51575b47-30f0-44d4-a5cc-537603b46e54
parent 9e5aee36
No related branches found
No related tags found
No related merge requests found
......@@ -77,29 +77,15 @@ const char *get_self_executable(int argc, char **argv)
return buf;
}
#import <sys/sysctl.h>
int get_number_cpus()
{
int mib[4];
size_t len = sizeof(numCPU);
/* set the mib for hw.ncpu */
mib[0] = CTL_HW;
mib[1] = HW_AVAILCPU; // alternatively, try HW_NCPU;
/* get the number of CPUs from the system */
sysctl(mib, 2, &numCPU, &len, NULL, 0);
if( numCPU < 1 )
{
mib[1] = HW_NCPU;
sysctl( mib, 2, &numCPU, &len, NULL, 0 );
if( numCPU < 1 )
{
numCPU = 1;
}
}
return numCPU;
int count ;
size_t size=sizeof(count) ;
if (sysctlbyname("hw.ncpu",&count,&size,NULL,0)) return 1;
return count;
}
#else
......
......@@ -13,3 +13,14 @@ const char *get_self_executable(int argc, char **argv)
return cstr;
}
#import <sys/sysctl.h>
int get_number_cpus()
{
int count ;
size_t size=sizeof(count) ;
if (sysctlbyname("hw.ncpu",&count,&size,NULL,0)) return 1;
return count;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment