diff options
Diffstat (limited to 'src/libgreen/stack.rs')
| -rw-r--r-- | src/libgreen/stack.rs | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/src/libgreen/stack.rs b/src/libgreen/stack.rs index f42d636cafb..2e385f75e1d 100644 --- a/src/libgreen/stack.rs +++ b/src/libgreen/stack.rs @@ -8,9 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use std::rt::env::max_cached_stacks; +use std::sync::atomics; use std::os::{errno, page_size, MemoryMap, MapReadable, MapWritable, - MapNonStandardFlags, MapVirtual}; + MapNonStandardFlags, MapVirtual, getenv}; use libc; /// A task's stack. The name "Stack" is a vestige of segmented stacks. @@ -151,6 +151,22 @@ impl StackPool { } } +fn max_cached_stacks() -> uint { + static mut AMT: atomics::AtomicUint = atomics::INIT_ATOMIC_UINT; + match unsafe { AMT.load(atomics::SeqCst) } { + 0 => {} + n => return n - 1, + } + let amt = getenv("RUST_MAX_CACHED_STACKS").and_then(|s| from_str(s.as_slice())); + // This default corresponds to 20M of cache per scheduler (at the + // default size). + let amt = amt.unwrap_or(10); + // 0 is our sentinel value, so ensure that we'll never see 0 after + // initialization has run + unsafe { AMT.store(amt + 1, atomics::SeqCst); } + return amt; +} + extern { fn rust_valgrind_stack_register(start: *libc::uintptr_t, end: *libc::uintptr_t) -> libc::c_uint; |
