Skip to content

Commit ae10b09

Browse files
author
Jorge Aparicio
committed
Move num_cpus from std::rt::util to std::os. Closes rust-lang#14707
1 parent 4b672a6 commit ae10b09

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

src/libstd/os.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ use libc::c_char;
5656
#[cfg(windows)]
5757
use str::OwnedStr;
5858

59+
/// Get the number of cores available
60+
pub fn num_cpus() -> uint {
61+
unsafe {
62+
return rust_get_num_cpus();
63+
}
64+
65+
extern {
66+
fn rust_get_num_cpus() -> libc::uintptr_t;
67+
}
68+
}
5969

6070
pub static TMPBUF_SZ : uint = 1000u;
6171
static BUF_BYTES : uint = 2048u;
@@ -1751,6 +1761,11 @@ mod tests {
17511761
n
17521762
}
17531763

1764+
#[test]
1765+
fn test_num_cpus() {
1766+
assert!(os::num_cpus() > 0);
1767+
}
1768+
17541769
#[test]
17551770
fn test_setenv() {
17561771
let n = make_rand_name();

src/libstd/rt/util.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,11 @@
1111
use from_str::FromStr;
1212
use from_str::from_str;
1313
use libc::uintptr_t;
14-
use libc;
1514
use option::{Some, None, Option};
1615
use os;
1716
use str::Str;
1817
use sync::atomics;
1918

20-
/// Get the number of cores available
21-
pub fn num_cpus() -> uint {
22-
unsafe {
23-
return rust_get_num_cpus();
24-
}
25-
26-
extern {
27-
fn rust_get_num_cpus() -> libc::uintptr_t;
28-
}
29-
}
30-
3119
/// Dynamically inquire about whether we're running under V.
3220
/// You should usually not use this unless your test definitely
3321
/// can't run correctly un-altered. Valgrind is there to help
@@ -81,7 +69,7 @@ pub fn default_sched_threads() -> uint {
8169
if limit_thread_creation_due_to_osx_and_valgrind() {
8270
1
8371
} else {
84-
num_cpus()
72+
os::num_cpus()
8573
}
8674
}
8775
}

0 commit comments

Comments
 (0)