Skip to content

Commit f82da81

Browse files
committed
std::rt: Pull RUST_MIN_STACK from the environment
1 parent eb61432 commit f82da81

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

src/libstd/rt/env.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010

1111
//! Runtime environment settings
1212
13+
use from_str::FromStr;
1314
use libc::{size_t, c_char, c_int};
15+
use option::{Some, None};
16+
use os;
17+
18+
// OLD RT stuff
1419

1520
pub struct Environment {
1621
/// The number of threads to use by default
@@ -47,3 +52,26 @@ pub fn get() -> &Environment {
4752
extern {
4853
fn rust_get_rt_env() -> &Environment;
4954
}
55+
56+
// NEW RT stuff
57+
58+
// Note that these are all accessed without any synchronization.
59+
// They are expected to be initialized once then left alone.
60+
61+
static mut MIN_STACK: uint = 2000000;
62+
63+
pub fn init() {
64+
unsafe {
65+
match os::getenv("RUST_MIN_STACK") {
66+
Some(s) => match FromStr::from_str(s) {
67+
Some(i) => MIN_STACK = i,
68+
None => ()
69+
},
70+
None => ()
71+
}
72+
}
73+
}
74+
75+
pub fn min_stack() -> uint {
76+
unsafe { MIN_STACK }
77+
}

src/libstd/rt/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ pub fn init(argc: int, argv: **u8, crate_map: *u8) {
212212
// Need to propagate the unsafety to `start`.
213213
unsafe {
214214
args::init(argc, argv);
215+
env::init();
215216
logging::init(crate_map);
216217
rust_update_gc_metadata(crate_map);
217218
}

src/libstd/rt/task.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use libc::{c_void, uintptr_t};
2020
use ptr;
2121
use prelude::*;
2222
use option::{Option, Some, None};
23+
use rt::env;
2324
use rt::kill::Death;
2425
use rt::local::Local;
2526
use rt::logging::StdErrLogger;
@@ -326,10 +327,9 @@ impl Drop for Task {
326327
impl Coroutine {
327328

328329
pub fn new(stack_pool: &mut StackPool, start: ~fn()) -> Coroutine {
329-
static MIN_STACK_SIZE: uint = 2000000; // XXX: Too much stack
330-
330+
let stack_size = env::min_stack();
331331
let start = Coroutine::build_start_wrapper(start);
332-
let mut stack = stack_pool.take_segment(MIN_STACK_SIZE);
332+
let mut stack = stack_pool.take_segment(stack_size);
333333
let initial_context = Context::new(start, &mut stack);
334334
Coroutine {
335335
current_stack_segment: stack,

0 commit comments

Comments
 (0)