]> git.lizzy.rs Git - rust.git/commitdiff
std::rt: Pull RUST_MIN_STACK from the environment
authorBrian Anderson <banderson@mozilla.com>
Mon, 5 Aug 2013 19:43:33 +0000 (12:43 -0700)
committerBrian Anderson <banderson@mozilla.com>
Wed, 7 Aug 2013 22:40:27 +0000 (15:40 -0700)
src/libstd/rt/env.rs
src/libstd/rt/mod.rs
src/libstd/rt/task.rs

index 1d7ff17314901bf50093e8cdeecef254c22a3017..6e671742fb6fdfa7fd8c8c71b8ed58fcbd34faca 100644 (file)
 
 //! 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 }
+}
index 760ca8a9adadcbae741cce4423728ffd6ea3e75e..5b22eace56f8a67025848ea93476a912ab80b458 100644 (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);
     }
index 2da44c2f33200beade4828cdb9ab155b6d746d73..aa6d51a480b2b9a232e5e440a97f9f9b8b5d49aa 100644 (file)
@@ -20,6 +20,7 @@
 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 @@ fn drop(&self) {
 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,