(index<- )        ./libstd/rt/env.rs

    git branch:    * master           5200215 auto merge of #14035 : alexcrichton/rust/experimental, r=huonw
    modified:    Fri May  9 13:02:28 2014
  1  // Copyright 2013 The Rust Project Developers. See the COPYRIGHT
  2  // file at the top-level directory of this distribution and at
  3  // http://rust-lang.org/COPYRIGHT.
  4  //
  5  // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
  6  // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
  7  // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
  8  // option. This file may not be copied, modified, or distributed
  9  // except according to those terms.
 10  
 11  //! Runtime environment settings
 12  
 13  use from_str::from_str;
 14  use option::{Some, None, Expect};
 15  use os;
 16  
 17  // Note that these are all accessed without any synchronization.
 18  // They are expected to be initialized once then left alone.
 19  
 20  static mut MIN_STACK: uint = 2 * 1024 * 1024;
 21  /// This default corresponds to 20M of cache per scheduler (at the default size).
 22  static mut MAX_CACHED_STACKS: uint = 10;
 23  static mut DEBUG_BORROW: bool = false;
 24  
 25  pub fn init() {
 26      unsafe {
 27          match os::getenv("RUST_MIN_STACK") {
 28              Some(s) => match from_str(s) {
 29                  Some(i) => MIN_STACK = i,
 30                  None => ()
 31              },
 32              None => ()
 33          }
 34          match os::getenv("RUST_MAX_CACHED_STACKS") {
 35              Some(max) => MAX_CACHED_STACKS = from_str(max).expect("expected positive integer in \
 36                                                                     RUST_MAX_CACHED_STACKS"),
 37              None => ()
 38          }
 39          match os::getenv("RUST_DEBUG_BORROW") {
 40              Some(_) => DEBUG_BORROW = true,
 41              None => ()
 42          }
 43      }
 44  }
 45  
 46  pub fn min_stack() -> uint {
 47      unsafe { MIN_STACK }
 48  }
 49  
 50  pub fn max_cached_stacks() -> uint {
 51      unsafe { MAX_CACHED_STACKS }
 52  }
 53  
 54  pub fn debug_borrow() -> bool {
 55      unsafe { DEBUG_BORROW }
 56  }