std::rt: Pull RUST_MIN_STACK from the environment

This commit is contained in:
Brian Anderson 2013-08-05 12:43:33 -07:00
parent eb6143257d
commit f82da818a7
3 changed files with 32 additions and 3 deletions

View file

@ -10,7 +10,12 @@
//! Runtime environment settings
use from_str::FromStr;
use libc::{size_t, c_char, c_int};
use option::{Some, None};
use os;
// OLD RT stuff
pub struct Environment {
/// The number of threads to use by default
@ -47,3 +52,26 @@ pub fn get() -> &Environment {
extern {
fn rust_get_rt_env() -> &Environment;
}
// NEW RT stuff
// Note that these are all accessed without any synchronization.
// They are expected to be initialized once then left alone.
static mut MIN_STACK: uint = 2000000;
pub fn init() {
unsafe {
match os::getenv("RUST_MIN_STACK") {
Some(s) => match FromStr::from_str(s) {
Some(i) => MIN_STACK = i,
None => ()
},
None => ()
}
}
}
pub fn min_stack() -> uint {
unsafe { MIN_STACK }
}

View file

@ -212,6 +212,7 @@ pub fn init(argc: int, argv: **u8, crate_map: *u8) {
// Need to propagate the unsafety to `start`.
unsafe {
args::init(argc, argv);
env::init();
logging::init(crate_map);
rust_update_gc_metadata(crate_map);
}

View file

@ -20,6 +20,7 @@ use libc::{c_void, uintptr_t};
use ptr;
use prelude::*;
use option::{Option, Some, None};
use rt::env;
use rt::kill::Death;
use rt::local::Local;
use rt::logging::StdErrLogger;
@ -326,10 +327,9 @@ impl Drop for Task {
impl Coroutine {
pub fn new(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine {
static MIN_STACK_SIZE: uint = 2000000; // XXX: Too much stack
let stack_size = env::min_stack();
let start = Coroutine::build_start_wrapper(start);
let mut stack = stack_pool.take_segment(MIN_STACK_SIZE);
let mut stack = stack_pool.take_segment(stack_size);
let initial_context = Context::new(start, &mut stack);
Coroutine {
current_stack_segment: stack,