diff options
| author | Brian Anderson <banderson@mozilla.com> | 2013-06-17 22:17:51 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2013-06-17 22:17:51 -0700 |
| commit | 3281f5b63792a57d2cea6e93446e63f44e1e3ea0 (patch) | |
| tree | 43d663351609bab2ce00e362f60969d0bb7a90ac /src/libstd/rt | |
| parent | 319cf6e465f203c794d71800808c2bd60a1e7613 (diff) | |
| download | rust-3281f5b63792a57d2cea6e93446e63f44e1e3ea0.tar.gz rust-3281f5b63792a57d2cea6e93446e63f44e1e3ea0.zip | |
std::rt: Add util mod and num_cpus function
Diffstat (limited to 'src/libstd/rt')
| -rw-r--r-- | src/libstd/rt/mod.rs | 3 | ||||
| -rw-r--r-- | src/libstd/rt/test.rs | 7 | ||||
| -rw-r--r-- | src/libstd/rt/util.rs | 22 |
3 files changed, 27 insertions, 5 deletions
diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 1724361cabc..10b5c78f99e 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 6e4fb9b1d94..36efcd91834 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 00000000000..39b9de90f34 --- /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 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 |
