about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorJorge Aparicio <japaric@linux.com>2014-06-16 15:36:07 -0500
committerAlex Crichton <alex@alexcrichton.com>2014-06-16 18:16:12 -0700
commit0439162d597d4abfebf93096e71ff45242efe6f0 (patch)
tree350ae4cbf240110f4309faf017fcf3cdd90724ca /src/libstd
parent88e157619019894bbd3ecda0e3a1c9be4ce89ad6 (diff)
downloadrust-0439162d597d4abfebf93096e71ff45242efe6f0.tar.gz
rust-0439162d597d4abfebf93096e71ff45242efe6f0.zip
Move `num_cpus` from `std::rt::util` to `std::os`. Closes #14707
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/os.rs15
-rw-r--r--src/libstd/rt/util.rs14
2 files changed, 16 insertions, 13 deletions
diff --git a/src/libstd/os.rs b/src/libstd/os.rs
index 0747e7ccbe3..dfbf61cc890 100644
--- a/src/libstd/os.rs
+++ b/src/libstd/os.rs
@@ -57,6 +57,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;
@@ -1763,6 +1773,11 @@ mod tests {
     }
 
     #[test]
+    fn test_num_cpus() {
+        assert!(os::num_cpus() > 0);
+    }
+
+    #[test]
     fn test_setenv() {
         let n = make_rand_name();
         setenv(n.as_slice(), "VALUE");
diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs
index 670d4aa2061..fa30ddbcc48 100644
--- a/src/libstd/rt/util.rs
+++ b/src/libstd/rt/util.rs
@@ -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
@@ -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()
             }
         }
     }