]> git.proxmox.com Git - rustc.git/blob - src/libstd/sys_common/thread.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / libstd / sys_common / thread.rs
1 // Copyright 2014 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 use alloc::boxed::FnBox;
12 use env;
13 use sync::atomic::{self, Ordering};
14 use sys::stack_overflow;
15 use sys::thread as imp;
16
17 #[allow(dead_code)]
18 pub unsafe fn start_thread(main: *mut u8) {
19 // Next, set up our stack overflow handler which may get triggered if we run
20 // out of stack.
21 let _handler = stack_overflow::Handler::new();
22
23 // Finally, let's run some code.
24 Box::from_raw(main as *mut Box<FnBox()>)()
25 }
26
27 pub fn min_stack() -> usize {
28 static MIN: atomic::AtomicUsize = atomic::AtomicUsize::new(0);
29 match MIN.load(Ordering::SeqCst) {
30 0 => {}
31 n => return n - 1,
32 }
33 let amt = env::var("RUST_MIN_STACK").ok().and_then(|s| s.parse().ok());
34 let amt = amt.unwrap_or(imp::DEFAULT_MIN_STACK_SIZE);
35
36 // 0 is our sentinel value, so ensure that we'll never see 0 after
37 // initialization has run
38 MIN.store(amt + 1, Ordering::SeqCst);
39 amt
40 }