about summary refs log tree commit diff
path: root/src/libgreen/stack.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-06-04 00:01:40 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-06-06 23:00:01 -0700
commit75014f7b1790e7ebdf13d38acc04dfdab6e450e9 (patch)
tree46fb046e002a37ba60f6e8b8ef5ee0675fbb7fd8 /src/libgreen/stack.rs
parentd743b8831e6dc5b390af112cc23159d667cf583b (diff)
downloadrust-75014f7b1790e7ebdf13d38acc04dfdab6e450e9.tar.gz
rust-75014f7b1790e7ebdf13d38acc04dfdab6e450e9.zip
libs: Fix miscellaneous fallout of librustrt
Diffstat (limited to 'src/libgreen/stack.rs')
-rw-r--r--src/libgreen/stack.rs20
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;