]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys_common/thread.rs
Auto merge of #68522 - estebank:impl-trait-sugg-2, r=oli-obk
[rust.git] / src / libstd / sys_common / thread.rs
1 use crate::env;
2 use crate::sync::atomic::{self, Ordering};
3 use crate::sys::stack_overflow;
4 use crate::sys::thread as imp;
5
6 #[allow(dead_code)]
7 pub unsafe fn start_thread(main: *mut u8) {
8     // Next, set up our stack overflow handler which may get triggered if we run
9     // out of stack.
10     let _handler = stack_overflow::Handler::new();
11
12     // Finally, let's run some code.
13     Box::from_raw(main as *mut Box<dyn FnOnce()>)()
14 }
15
16 pub fn min_stack() -> usize {
17     static MIN: atomic::AtomicUsize = atomic::AtomicUsize::new(0);
18     match MIN.load(Ordering::SeqCst) {
19         0 => {}
20         n => return n - 1,
21     }
22     let amt = env::var("RUST_MIN_STACK").ok().and_then(|s| s.parse().ok());
23     let amt = amt.unwrap_or(imp::DEFAULT_MIN_STACK_SIZE);
24
25     // 0 is our sentinel value, so ensure that we'll never see 0 after
26     // initialization has run
27     MIN.store(amt + 1, Ordering::SeqCst);
28     amt
29 }