Skip to content

Reexport num_cpus in std::os. Closes #14707 #14938

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/libstd/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ use libc::c_char;
#[cfg(windows)]
use str::OwnedStr;

/// Get the number of cores available
pub fn num_cpus() -> uint {
unsafe {
return rust_get_num_cpus();
}

extern {
fn rust_get_num_cpus() -> libc::uintptr_t;
}
}

pub static TMPBUF_SZ : uint = 1000u;
static BUF_BYTES : uint = 2048u;
Expand Down Expand Up @@ -1751,6 +1761,11 @@ mod tests {
n
}

#[test]
fn test_num_cpus() {
assert!(os::num_cpus() > 0);
}

#[test]
fn test_setenv() {
let n = make_rand_name();
Expand Down
14 changes: 1 addition & 13 deletions src/libstd/rt/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,11 @@
use from_str::FromStr;
use from_str::from_str;
use libc::uintptr_t;
use libc;
use option::{Some, None, Option};
use os;
use str::Str;
use sync::atomics;

/// Get the number of cores available
pub fn num_cpus() -> uint {
unsafe {
return rust_get_num_cpus();
}

extern {
fn rust_get_num_cpus() -> libc::uintptr_t;
}
}

/// Dynamically inquire about whether we're running under V.
/// You should usually not use this unless your test definitely
/// can't run correctly un-altered. Valgrind is there to help
Expand Down Expand Up @@ -81,7 +69,7 @@ pub fn default_sched_threads() -> uint {
if limit_thread_creation_due_to_osx_and_valgrind() {
1
} else {
num_cpus()
os::num_cpus()
}
}
}
Expand Down