]> git.lizzy.rs Git - rust.git/blob - src/libstd/rt/env.rs
std: Remove generics from Option::expect
[rust.git] / src / libstd / rt / env.rs
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};
15 use os;
16 use str::Str;
17
18 // Note that these are all accessed without any synchronization.
19 // They are expected to be initialized once then left alone.
20
21 static mut MIN_STACK: uint = 2 * 1024 * 1024;
22 /// This default corresponds to 20M of cache per scheduler (at the default size).
23 static mut MAX_CACHED_STACKS: uint = 10;
24 static mut DEBUG_BORROW: bool = false;
25
26 pub fn init() {
27     unsafe {
28         match os::getenv("RUST_MIN_STACK") {
29             Some(s) => match from_str(s.as_slice()) {
30                 Some(i) => MIN_STACK = i,
31                 None => ()
32             },
33             None => ()
34         }
35         match os::getenv("RUST_MAX_CACHED_STACKS") {
36             Some(max) => {
37                 MAX_CACHED_STACKS =
38                     from_str(max.as_slice()).expect("expected positive \
39                                                      integer in \
40                                                      RUST_MAX_CACHED_STACKS")
41             }
42             None => ()
43         }
44         match os::getenv("RUST_DEBUG_BORROW") {
45             Some(_) => DEBUG_BORROW = true,
46             None => ()
47         }
48     }
49 }
50
51 pub fn min_stack() -> uint {
52     unsafe { MIN_STACK }
53 }
54
55 pub fn max_cached_stacks() -> uint {
56     unsafe { MAX_CACHED_STACKS }
57 }
58
59 pub fn debug_borrow() -> bool {
60     unsafe { DEBUG_BORROW }
61 }