//! 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
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 }
+}
// Need to propagate the unsafety to `start`.
unsafe {
args::init(argc, argv);
+ env::init();
logging::init(crate_map);
rust_update_gc_metadata(crate_map);
}
use ptr;
use prelude::*;
use option::{Option, Some, None};
+use rt::env;
use rt::kill::Death;
use rt::local::Local;
use rt::logging::StdErrLogger;
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,