diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 1724361cabcc..10b5c78f99e5 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -139,6 +139,9 @@ pub mod join_latch; pub mod metrics; +// FIXME #5248 shouldn't be pub +/// Just stuff +pub mod util; /// Set up a default runtime configuration, given compiler-supplied arguments. /// diff --git a/src/libstd/rt/test.rs b/src/libstd/rt/test.rs index 6e4fb9b1d940..36efcd91834b 100644 --- a/src/libstd/rt/test.rs +++ b/src/libstd/rt/test.rs @@ -63,11 +63,11 @@ pub fn run_in_newsched_task(f: ~fn()) { /// in one of the schedulers. The schedulers will stay alive /// until the function `f` returns. pub fn run_in_mt_newsched_task(f: ~fn()) { - use libc; use os; use from_str::FromStr; use rt::uv::uvio::UvEventLoop; use rt::sched::Shutdown; + use rt::util; let f_cell = Cell::new(f); @@ -78,7 +78,7 @@ pub fn run_in_mt_newsched_task(f: ~fn()) { // Using more threads than cores in test code // to force the OS to preempt them frequently. // Assuming that this help stress test concurrent types. - rust_get_num_cpus() * 2 + util::num_cpus() * 2 } }; @@ -132,9 +132,6 @@ pub fn run_in_mt_newsched_task(f: ~fn()) { let _threads = threads; } - extern { - fn rust_get_num_cpus() -> libc::uintptr_t; - } } // THIS IS AWFUL. Copy-pasted the above initialization function but diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs new file mode 100644 index 000000000000..39b9de90f347 --- /dev/null +++ b/src/libstd/rt/util.rs @@ -0,0 +1,22 @@ +// Copyright 2013 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use libc; + +/// 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; + } +} \ No newline at end of file