Skip to content

Commit b2b5063

Browse files
Tobias Schaffnerhumenda
Tobias Schaffner
authored andcommitted
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.
1 parent 5d1a9d7 commit b2b5063

File tree

7 files changed

+31
-25
lines changed

7 files changed

+31
-25
lines changed

src/libstd/sys/redox/thread.rs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ use sys_common::thread::start_thread;
1616
use sys::{cvt, syscall};
1717
use time::Duration;
1818

19+
pub const DEFAULT_MIN_STACK_SIZE: usize = 2 * 1024 * 1024;
20+
1921
pub struct Thread {
2022
id: usize,
2123
}

src/libstd/sys/unix/l4re.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,11 @@ pub mod net {
104104
impl AsInner<libc::c_int> for Socket {
105105
fn as_inner(&self) -> &libc::c_int { self.0.as_inner() }
106106
}
107-
107+
108108
impl FromInner<libc::c_int> for Socket {
109109
fn from_inner(fd: libc::c_int) -> Socket { Socket(FileDesc::new(fd)) }
110110
}
111-
111+
112112
impl IntoInner<libc::c_int> for Socket {
113113
fn into_inner(self) -> libc::c_int { self.0.into_raw() }
114114
}

src/libstd/sys/unix/thread.rs

+5
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ use time::Duration;
2020

2121
use sys_common::thread::*;
2222

23+
#[cfg(not(target_os = "l4re"))]
24+
pub const DEFAULT_MIN_STACK_SIZE: usize = 2 * 1024 * 1024;
25+
#[cfg(target_os = "l4re")]
26+
pub const DEFAULT_MIN_STACK_SIZE: usize = 1024 * 1024;
27+
2328
pub struct Thread {
2429
id: libc::pthread_t,
2530
}

src/libstd/sys/windows/thread.rs

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ use sys::handle::Handle;
1919
use sys_common::thread::*;
2020
use time::Duration;
2121

22+
pub const DEFAULT_MIN_STACK_SIZE: usize = 2 * 1024 * 1024;
23+
2224
pub struct Thread {
2325
handle: Handle
2426
}

src/libstd/sys_common/thread.rs

+18
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use env;
1112
use alloc::boxed::FnBox;
1213
use libc;
14+
use sync::atomic::{self, Ordering};
1315
use sys::stack_overflow;
16+
use sys::thread as imp;
1417

1518
pub unsafe fn start_thread(main: *mut libc::c_void) {
1619
// 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) {
2023
// Finally, let's run some code.
2124
Box::from_raw(main as *mut Box<FnBox()>)()
2225
}
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+
}

src/libstd/sys_common/util.rs

-21
Original file line numberDiff line numberDiff line change
@@ -8,32 +8,11 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use env;
1211
use fmt;
1312
use io::prelude::*;
14-
use sync::atomic::{self, Ordering};
1513
use sys::stdio::Stderr;
1614
use thread;
1715

18-
pub fn min_stack() -> usize {
19-
static MIN: atomic::AtomicUsize = atomic::AtomicUsize::new(0);
20-
match MIN.load(Ordering::SeqCst) {
21-
0 => {}
22-
n => return n - 1,
23-
}
24-
let amt = env::var("RUST_MIN_STACK").ok().and_then(|s| s.parse().ok());
25-
#[cfg(not(target_os = "l4re"))]
26-
let amt = amt.unwrap_or(2 * 1024 * 1024);
27-
// L4Re only supports a maximum of 1Mb per default.
28-
#[cfg(target_os = "l4re")]
29-
let amt = amt.unwrap_or(1024 * 1024);
30-
31-
// 0 is our sentinel value, so ensure that we'll never see 0 after
32-
// initialization has run
33-
MIN.store(amt + 1, Ordering::SeqCst);
34-
amt
35-
}
36-
3716
pub fn dumb_print(args: fmt::Arguments) {
3817
let _ = Stderr::new().map(|mut stderr| stderr.write_fmt(args));
3918
}

src/libstd/thread/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ use sync::{Mutex, Condvar, Arc};
174174
use sys::thread as imp;
175175
use sys_common::mutex;
176176
use sys_common::thread_info;
177-
use sys_common::util;
177+
use sys_common::thread;
178178
use sys_common::{AsInner, IntoInner};
179179
use time::Duration;
180180

@@ -374,7 +374,7 @@ impl Builder {
374374
{
375375
let Builder { name, stack_size } = self;
376376

377-
let stack_size = stack_size.unwrap_or_else(util::min_stack);
377+
let stack_size = stack_size.unwrap_or_else(thread::min_stack);
378378

379379
let my_thread = Thread::new(name);
380380
let their_thread = my_thread.clone();

0 commit comments

Comments
 (0)