Skip to content

Commit 6e023e7

Browse files
committed
---
yaml --- r: 96919 b: refs/heads/dist-snap c: 780afea h: refs/heads/master i: 96917: 11b7573 96915: a50fd6e 96911: fef29b6 v: v3
1 parent 4775786 commit 6e023e7

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: c274a6888410ce3e357e014568b43310ed787d36
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 7554f5c58f840b648bc3c5b2d24d0df6683eed03
9+
refs/heads/dist-snap: 780afeaf0a2c063c68d91660eb15a3314f1eadcb
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libstd/rt/thread.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub struct Thread<T> {
3333
priv packet: ~Option<T>,
3434
}
3535

36-
static DEFAULT_STACK_SIZE: libc::size_t = 1024 * 1024;
36+
static DEFAULT_STACK_SIZE: uint = 1024 * 1024;
3737

3838
// This is the starting point of rust os threads. The first thing we do
3939
// is make sure that we don't trigger __morestack (also why this has a
@@ -84,7 +84,7 @@ impl Thread<()> {
8484
*cast::transmute::<&~Option<T>, **mut Option<T>>(&packet)
8585
};
8686
let main: proc() = proc() unsafe { *packet2 = Some(main()); };
87-
let native = unsafe { imp::create(~main) };
87+
let native = unsafe { imp::create(stack, ~main) };
8888

8989
Thread {
9090
native: native,
@@ -100,8 +100,14 @@ impl Thread<()> {
100100
/// systems. Note that platforms may not keep the main program alive even if
101101
/// there are detached thread still running around.
102102
pub fn spawn(main: proc()) {
103+
Thread::spawn_stack(DEFAULT_STACK_SIZE, main)
104+
}
105+
106+
/// Performs the same functionality as `spawn`, but explicitly specifies a
107+
/// stack size for the new thread.
108+
pub fn spawn_stack(stack: uint, main: proc()) {
103109
unsafe {
104-
let handle = imp::create(~main);
110+
let handle = imp::create(stack, ~main);
105111
imp::detach(handle);
106112
}
107113
}
@@ -145,13 +151,15 @@ mod imp {
145151
use libc::types::os::arch::extra::{LPSECURITY_ATTRIBUTES, SIZE_T, BOOL,
146152
LPVOID, DWORD, LPDWORD, HANDLE};
147153
use ptr;
154+
use libc;
155+
use cast;
148156

149157
pub type rust_thread = HANDLE;
150158
pub type rust_thread_return = DWORD;
151159

152-
pub unsafe fn create(p: ~proc()) -> rust_thread {
160+
pub unsafe fn create(stack: uint, p: ~proc()) -> rust_thread {
153161
let arg: *mut libc::c_void = cast::transmute(p);
154-
CreateThread(ptr::mut_null(), DEFAULT_STACK_SIZE, super::thread_start,
162+
CreateThread(ptr::mut_null(), stack as libc::size_t, super::thread_start,
155163
arg, 0, ptr::mut_null())
156164
}
157165

@@ -189,17 +197,17 @@ mod imp {
189197
use libc::consts::os::posix01::PTHREAD_CREATE_JOINABLE;
190198
use libc;
191199
use ptr;
192-
use super::DEFAULT_STACK_SIZE;
193200
use unstable::intrinsics;
194201

195202
pub type rust_thread = libc::pthread_t;
196203
pub type rust_thread_return = *libc::c_void;
197204

198-
pub unsafe fn create(p: ~proc()) -> rust_thread {
205+
pub unsafe fn create(stack: uint, p: ~proc()) -> rust_thread {
199206
let mut native: libc::pthread_t = intrinsics::uninit();
200207
let mut attr: libc::pthread_attr_t = intrinsics::uninit();
201208
assert_eq!(pthread_attr_init(&mut attr), 0);
202-
assert_eq!(pthread_attr_setstacksize(&mut attr, DEFAULT_STACK_SIZE), 0);
209+
assert_eq!(pthread_attr_setstacksize(&mut attr,
210+
stack as libc::size_t), 0);
203211
assert_eq!(pthread_attr_setdetachstate(&mut attr,
204212
PTHREAD_CREATE_JOINABLE), 0);
205213

0 commit comments

Comments
 (0)