diff options
| author | Tobias Schaffner <tschaff@genua.de> | 2017-09-09 11:09:34 +0200 |
|---|---|---|
| committer | Sebastian Humenda <shumenda@gmx.de> | 2017-09-13 10:56:41 +0200 |
| commit | b2b50635172254777d16d0fc6112e6d5b68b63f2 (patch) | |
| tree | 37e3b004a9dd7ab32ba846aab3ae738962e09259 /src/libstd | |
| parent | 5d1a9d7ae761cb7fd88b37bab0d55f59379462ef (diff) | |
| download | rust-b2b50635172254777d16d0fc6112e6d5b68b63f2.tar.gz rust-b2b50635172254777d16d0fc6112e6d5b68b63f2.zip | |
Move default stack min size to thread implementations
The default min stack size value is smaller on l4re and therefore this value has to be different depending on the platform.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/sys/redox/thread.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/unix/l4re.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/unix/thread.rs | 5 | ||||
| -rw-r--r-- | src/libstd/sys/windows/thread.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys_common/thread.rs | 18 | ||||
| -rw-r--r-- | src/libstd/sys_common/util.rs | 21 | ||||
| -rw-r--r-- | src/libstd/thread/mod.rs | 4 |
7 files changed, 31 insertions, 25 deletions
diff --git a/src/libstd/sys/redox/thread.rs b/src/libstd/sys/redox/thread.rs index b2c0e285f06..c4aad8d86f8 100644 --- a/src/libstd/sys/redox/thread.rs +++ b/src/libstd/sys/redox/thread.rs @@ -16,6 +16,8 @@ use sys_common::thread::start_thread; use sys::{cvt, syscall}; use time::Duration; +pub const DEFAULT_MIN_STACK_SIZE: usize = 2 * 1024 * 1024; + pub struct Thread { id: usize, } diff --git a/src/libstd/sys/unix/l4re.rs b/src/libstd/sys/unix/l4re.rs index e07c864a6cb..21218489679 100644 --- a/src/libstd/sys/unix/l4re.rs +++ b/src/libstd/sys/unix/l4re.rs @@ -104,11 +104,11 @@ pub mod net { impl AsInner<libc::c_int> for Socket { fn as_inner(&self) -> &libc::c_int { self.0.as_inner() } } - + impl FromInner<libc::c_int> for Socket { fn from_inner(fd: libc::c_int) -> Socket { Socket(FileDesc::new(fd)) } } - + impl IntoInner<libc::c_int> for Socket { fn into_inner(self) -> libc::c_int { self.0.into_raw() } } diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 60bce7924cd..6c4a3324296 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -20,6 +20,11 @@ use time::Duration; use sys_common::thread::*; +#[cfg(not(target_os = "l4re"))] +pub const DEFAULT_MIN_STACK_SIZE: usize = 2 * 1024 * 1024; +#[cfg(target_os = "l4re")] +pub const DEFAULT_MIN_STACK_SIZE: usize = 1024 * 1024; + pub struct Thread { id: libc::pthread_t, } diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index 2cdd86e88b0..6aea9d1fb56 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -19,6 +19,8 @@ use sys::handle::Handle; use sys_common::thread::*; use time::Duration; +pub const DEFAULT_MIN_STACK_SIZE: usize = 2 * 1024 * 1024; + pub struct Thread { handle: Handle } diff --git a/src/libstd/sys_common/thread.rs b/src/libstd/sys_common/thread.rs index 3ee160da5fa..87fb34a9dec 100644 --- a/src/libstd/sys_common/thread.rs +++ b/src/libstd/sys_common/thread.rs @@ -8,9 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use env; use alloc::boxed::FnBox; use libc; +use sync::atomic::{self, Ordering}; use sys::stack_overflow; +use sys::thread as imp; pub unsafe fn start_thread(main: *mut libc::c_void) { // Next, set up our stack overflow handler which may get triggered if we run @@ -20,3 +23,18 @@ pub unsafe fn start_thread(main: *mut libc::c_void) { // Finally, let's run some code. Box::from_raw(main as *mut Box<FnBox()>)() } + +pub fn min_stack() -> usize { + static MIN: atomic::AtomicUsize = atomic::AtomicUsize::new(0); + match MIN.load(Ordering::SeqCst) { + 0 => {} + n => return n - 1, + } + let amt = env::var("RUST_MIN_STACK").ok().and_then(|s| s.parse().ok()); + let amt = amt.unwrap_or(imp::DEFAULT_MIN_STACK_SIZE); + + // 0 is our sentinel value, so ensure that we'll never see 0 after + // initialization has run + MIN.store(amt + 1, Ordering::SeqCst); + amt +} diff --git a/src/libstd/sys_common/util.rs b/src/libstd/sys_common/util.rs index 41be6f43763..a391c7cc6ef 100644 --- a/src/libstd/sys_common/util.rs +++ b/src/libstd/sys_common/util.rs @@ -8,32 +8,11 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use env; use fmt; use io::prelude::*; -use sync::atomic::{self, Ordering}; use sys::stdio::Stderr; use thread; -pub fn min_stack() -> usize { - static MIN: atomic::AtomicUsize = atomic::AtomicUsize::new(0); - match MIN.load(Ordering::SeqCst) { - 0 => {} - n => return n - 1, - } - let amt = env::var("RUST_MIN_STACK").ok().and_then(|s| s.parse().ok()); - #[cfg(not(target_os = "l4re"))] - let amt = amt.unwrap_or(2 * 1024 * 1024); - // L4Re only supports a maximum of 1Mb per default. - #[cfg(target_os = "l4re")] - let amt = amt.unwrap_or(1024 * 1024); - - // 0 is our sentinel value, so ensure that we'll never see 0 after - // initialization has run - MIN.store(amt + 1, Ordering::SeqCst); - amt -} - pub fn dumb_print(args: fmt::Arguments) { let _ = Stderr::new().map(|mut stderr| stderr.write_fmt(args)); } diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 4912ff93abd..ca01eaefcae 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -174,7 +174,7 @@ use sync::{Mutex, Condvar, Arc}; use sys::thread as imp; use sys_common::mutex; use sys_common::thread_info; -use sys_common::util; +use sys_common::thread; use sys_common::{AsInner, IntoInner}; use time::Duration; @@ -374,7 +374,7 @@ impl Builder { { let Builder { name, stack_size } = self; - let stack_size = stack_size.unwrap_or_else(util::min_stack); + let stack_size = stack_size.unwrap_or_else(thread::min_stack); let my_thread = Thread::new(name); let their_thread = my_thread.clone(); |
