diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-07-25 17:50:08 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-07-26 11:12:20 -0700 |
| commit | 49a98f1508054556d1301ded432821f1bc4e1c98 (patch) | |
| tree | bf32dc4593b6bbfd91ada4c900972851848ff281 /src/rt/rust.cpp | |
| parent | e37dd2646a4808fff5647bc8d1a45914cd157c53 (diff) | |
| download | rust-49a98f1508054556d1301ded432821f1bc4e1c98.tar.gz rust-49a98f1508054556d1301ded432821f1bc4e1c98.zip | |
Base scheduler threads on number of cores. Closes #739
Diffstat (limited to 'src/rt/rust.cpp')
| -rw-r--r-- | src/rt/rust.cpp | 44 |
1 files changed, 41 insertions, 3 deletions
diff --git a/src/rt/rust.cpp b/src/rt/rust.cpp index c487bee954c..029532363c8 100644 --- a/src/rt/rust.cpp +++ b/src/rt/rust.cpp @@ -75,6 +75,46 @@ command_line_args : public kernel_owned<command_line_args> } }; + +#if defined(__WIN32__) +int get_num_cpus() { + SYSTEM_INFO sysinfo; + GetSystemInfo(&sysinfo); + + return (int) sysinfo.dwNumberOfProcessors; +} +#elif defined(__BSD__) +int get_num_cpus() { + /* swiped from http://stackoverflow.com/questions/150355/ + programmatically-find-the-number-of-cores-on-a-machine */ + + unsigned int numCPU; + 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; +} +#elif defined(__GNUC__) +int get_num_cpus() { + return sysconf(_SC_NPROCESSORS_ONLN); +} +#endif + int get_num_threads() { char *env = getenv("RUST_THREADS"); @@ -83,9 +123,7 @@ int get_num_threads() if(num > 0) return num; } - // FIXME: in this case, determine the number of CPUs present on the - // machine. - return 1; + return get_num_cpus(); } /** |
