@@ -53,7 +53,9 @@ use failure;
53
53
use os;
54
54
use thunk:: Thunk ;
55
55
use kinds:: Send ;
56
+ use thread:: Thread ;
56
57
use sys_common;
58
+ use sys_common:: thread:: { mod, NewThread } ;
57
59
58
60
// Reexport some of our utilities which are expected by other crates.
59
61
pub use self :: util:: { default_sched_threads, min_stack, running_on_valgrind} ;
@@ -73,8 +75,6 @@ pub mod mutex;
73
75
pub mod thread;
74
76
pub mod exclusive;
75
77
pub mod util;
76
- pub mod local;
77
- pub mod task;
78
78
pub mod unwind;
79
79
80
80
mod args;
@@ -98,8 +98,8 @@ pub fn init(argc: int, argv: *const *const u8) {
98
98
// Need to propagate the unsafety to `start`.
99
99
unsafe {
100
100
args:: init ( argc, argv) ;
101
- local_ptr :: init ( ) ;
102
- thread :: init ( ) ;
101
+ sys :: thread :: guard :: init ( ) ;
102
+ sys :: stack_overflow :: init ( ) ;
103
103
unwind:: register ( failure:: on_fail) ;
104
104
}
105
105
}
@@ -125,9 +125,6 @@ fn lang_start(main: *const u8, argc: int, argv: *const *const u8) -> int {
125
125
/// This procedure is guaranteed to run on the thread calling this function, but
126
126
/// the stack bounds for this rust task will *not* be set. Care must be taken
127
127
/// for this function to not overflow its stack.
128
- ///
129
- /// This function will only return once *all* native threads in the system have
130
- /// exited.
131
128
pub fn start ( argc : int , argv : * const * const u8 , main : Thunk ) -> int {
132
129
use prelude:: * ;
133
130
use rt;
@@ -143,11 +140,9 @@ pub fn start(argc: int, argv: *const *const u8, main: Thunk) -> int {
143
140
// frames above our current position.
144
141
let my_stack_bottom = my_stack_top + 20000 - OS_DEFAULT_STACK_ESTIMATE ;
145
142
146
- // When using libgreen, one of the first things that we do is to turn off
147
- // the SIGPIPE signal (set it to ignore). By default, some platforms will
148
- // send a *signal* when a EPIPE error would otherwise be delivered. This
149
- // runtime doesn't install a SIGPIPE handler, causing it to kill the
150
- // program, which isn't exactly what we want!
143
+ // By default, some platforms will send a *signal* when a EPIPE error would
144
+ // otherwise be delivered. This runtime doesn't install a SIGPIPE handler,
145
+ // causing it to kill the program, which isn't exactly what we want!
151
146
//
152
147
// Hence, we set SIGPIPE to ignore when the program starts up in order to
153
148
// prevent this problem.
@@ -163,17 +158,18 @@ pub fn start(argc: int, argv: *const *const u8, main: Thunk) -> int {
163
158
164
159
init ( argc, argv) ;
165
160
let mut exit_code = None ;
166
- let mut main = Some ( main) ;
167
- let mut task = box Task :: new ( Some ( ( my_stack_bottom, my_stack_top) ) ,
168
- Some ( rt:: thread:: main_guard_page ( ) ) ) ;
169
- task. name = Some ( str:: Slice ( "<main>" ) ) ;
170
- drop ( task. run ( || {
161
+
162
+ let thread: std:: Thread = NewThread :: new ( Some ( "<main>" . into_string ( ) ) ) ;
163
+ thread_info:: set ( ( my_stack_bottom, my_stack_top) ,
164
+ unsafe { sys:: thread:: guard:: main ( ) } ,
165
+ thread) ;
166
+ unwind:: try ( || {
171
167
unsafe {
172
168
sys_common:: stack:: record_os_managed_stack_bounds ( my_stack_bottom, my_stack_top) ;
173
169
}
174
170
( main. take ( ) . unwrap ( ) ) . invoke ( ( ) ) ;
175
171
exit_code = Some ( os:: get_exit_status ( ) ) ;
176
- } ) . destroy ( ) ) ;
172
+ } ) ;
177
173
unsafe { cleanup ( ) ; }
178
174
// If the exit code wasn't set, then the task block must have panicked.
179
175
return exit_code. unwrap_or ( rt:: DEFAULT_ERROR_CODE ) ;
@@ -207,8 +203,7 @@ pub fn at_exit(f: proc():Send) {
207
203
/// undefined behavior.
208
204
pub unsafe fn cleanup ( ) {
209
205
args:: cleanup ( ) ;
210
- thread:: cleanup ( ) ;
211
- local_ptr:: cleanup ( ) ;
206
+ sys:: stack_overflow:: cleanup ( ) ;
212
207
}
213
208
214
209
// FIXME: these probably shouldn't be public...
0 commit comments