]> git.lizzy.rs Git - rust.git/commitdiff
Move default stack min size to thread implementations
authorTobias Schaffner <tschaff@genua.de>
Sat, 9 Sep 2017 09:09:34 +0000 (11:09 +0200)
committerSebastian Humenda <shumenda@gmx.de>
Wed, 13 Sep 2017 08:56:41 +0000 (10:56 +0200)
The default min stack size value is smaller on l4re and therefore
this value has to be different depending on the platform.

src/libstd/sys/redox/thread.rs
src/libstd/sys/unix/l4re.rs
src/libstd/sys/unix/thread.rs
src/libstd/sys/windows/thread.rs
src/libstd/sys_common/thread.rs
src/libstd/sys_common/util.rs
src/libstd/thread/mod.rs

index b2c0e285f0663b2d856a06ef415ac87624696ecb..c4aad8d86f8b1f5e4b6fba452c4eb64e9476cf6d 100644 (file)
@@ -16,6 +16,8 @@
 use sys::{cvt, syscall};
 use time::Duration;
 
+pub const DEFAULT_MIN_STACK_SIZE: usize = 2 * 1024 * 1024;
+
 pub struct Thread {
     id: usize,
 }
index e07c864a6cbdc05d5b5513ca5e4ff9e4d2a4d417..21218489679393a92a655bf0012caa5ad242f962 100644 (file)
@@ -104,11 +104,11 @@ pub fn take_error(&self) -> io::Result<Option<io::Error>> {
     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() }
     }
index 60bce7924cdd8ee1ecfb82871ea303952a36335f..6c4a332429646be75c156884d409d8c090c7bdb3 100644 (file)
 
 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,
 }
index 2cdd86e88b0a074eb87125792b9f888aeb9eaaa3..6aea9d1fb560f118379fe7d0c4c8dbd7c26ece2a 100644 (file)
@@ -19,6 +19,8 @@
 use sys_common::thread::*;
 use time::Duration;
 
+pub const DEFAULT_MIN_STACK_SIZE: usize = 2 * 1024 * 1024;
+
 pub struct Thread {
     handle: Handle
 }
index 3ee160da5fa5b7876ab1a2c957b77c9cc3aa75f8..87fb34a9dec06459f95806377a451db8bbc27648 100644 (file)
@@ -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
+}
index 41be6f4376348b0746a541a7453708b2561f300d..a391c7cc6ef0c959c2e25eaf0bddf175cbb59cec 100644 (file)
@@ -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));
 }
index 4912ff93abdb389c19fc458398234220fd0c4b35..ca01eaefcaef4c8ac7ebb4a7b453d3e2f4390429 100644 (file)
 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 @@ pub fn spawn<F, T>(self, f: F) -> io::Result<JoinHandle<T>> where
     {
         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();