]> git.lizzy.rs Git - rust.git/commitdiff
Move `num_cpus` from `std::rt::util` to `std::os`. Closes #14707
authorJorge Aparicio <japaric@linux.com>
Mon, 16 Jun 2014 20:36:07 +0000 (15:36 -0500)
committerAlex Crichton <alex@alexcrichton.com>
Tue, 17 Jun 2014 01:16:12 +0000 (18:16 -0700)
src/libstd/os.rs
src/libstd/rt/util.rs

index 0747e7ccbe3fd98c7e4ba7466ddb981525934cc7..dfbf61cc890b7f12282213f43e49f1a4eedbc4b7 100644 (file)
 #[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;
@@ -1762,6 +1772,11 @@ fn make_rand_name() -> String {
         n
     }
 
+    #[test]
+    fn test_num_cpus() {
+        assert!(os::num_cpus() > 0);
+    }
+
     #[test]
     fn test_setenv() {
         let n = make_rand_name();
index 670d4aa2061f1e0f477c077edd2c56041e6daf33..fa30ddbcc48b5cb2573ba9144dd9c5fcc0438969 100644 (file)
 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()
             }
         }
     }