std::rt: Add util mod and num_cpus function

This commit is contained in:
Brian Anderson 2013-06-17 22:17:51 -07:00
parent 319cf6e465
commit 3281f5b637
3 changed files with 27 additions and 5 deletions

View file

@ -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.
///

View file

@ -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

22
src/libstd/rt/util.rs Normal file
View file

@ -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;
}
}