Commit a7986e2927b0f0c4c769a68d4e1c0f1a5edf2b22
1 parent
9e5aee36
make cpu count work on osx
git-svn-id: http://svn.net-core.org/repos/t-engine4@2605 51575b47-30f0-44d4-a5cc-537603b46e54
Showing
2 changed files
with
18 additions
and
21 deletions
... | ... | @@ -77,29 +77,15 @@ const char *get_self_executable(int argc, char **argv) |
77 | 77 | return buf; |
78 | 78 | } |
79 | 79 | |
80 | +#import <sys/sysctl.h> | |
81 | + | |
80 | 82 | int get_number_cpus() |
81 | 83 | { |
82 | - int mib[4]; | |
83 | - size_t len = sizeof(numCPU); | |
84 | - | |
85 | - /* set the mib for hw.ncpu */ | |
86 | - mib[0] = CTL_HW; | |
87 | - mib[1] = HW_AVAILCPU; // alternatively, try HW_NCPU; | |
88 | - | |
89 | - /* get the number of CPUs from the system */ | |
90 | - sysctl(mib, 2, &numCPU, &len, NULL, 0); | |
91 | - | |
92 | - if( numCPU < 1 ) | |
93 | - { | |
94 | - mib[1] = HW_NCPU; | |
95 | - sysctl( mib, 2, &numCPU, &len, NULL, 0 ); | |
96 | - | |
97 | - if( numCPU < 1 ) | |
98 | - { | |
99 | - numCPU = 1; | |
100 | - } | |
101 | - } | |
102 | - return numCPU; | |
84 | + int count ; | |
85 | + size_t size=sizeof(count) ; | |
86 | + | |
87 | + if (sysctlbyname("hw.ncpu",&count,&size,NULL,0)) return 1; | |
88 | + return count; | |
103 | 89 | } |
104 | 90 | |
105 | 91 | #else | ... | ... |
... | ... | @@ -13,3 +13,14 @@ const char *get_self_executable(int argc, char **argv) |
13 | 13 | |
14 | 14 | return cstr; |
15 | 15 | } |
16 | + | |
17 | +#import <sys/sysctl.h> | |
18 | + | |
19 | +int get_number_cpus() | |
20 | +{ | |
21 | + int count ; | |
22 | + size_t size=sizeof(count) ; | |
23 | + | |
24 | + if (sysctlbyname("hw.ncpu",&count,&size,NULL,0)) return 1; | |
25 | + return count; | |
26 | +} | ... | ... |
-
Please register or login to post a comment