std: Make os::set_exit_status work with newsched
This commit is contained in:
parent
ec6d4a1733
commit
07e52eb7fc
@ -1134,8 +1134,15 @@ pub fn last_os_error() -> ~str {
|
||||
* ignored and the process exits with the default failure status
|
||||
*/
|
||||
pub fn set_exit_status(code: int) {
|
||||
unsafe {
|
||||
rustrt::rust_set_exit_status(code as libc::intptr_t);
|
||||
use rt;
|
||||
use rt::OldTaskContext;
|
||||
|
||||
if rt::context() == OldTaskContext {
|
||||
unsafe {
|
||||
rustrt::rust_set_exit_status(code as libc::intptr_t);
|
||||
}
|
||||
} else {
|
||||
rt::util::set_exit_status(code);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -260,7 +260,15 @@ pub fn run(main: ~fn()) -> int {
|
||||
}
|
||||
|
||||
unsafe {
|
||||
let exit_code = if exit_success { 0 } else { DEFAULT_ERROR_CODE };
|
||||
let exit_code = if exit_success {
|
||||
use rt::util;
|
||||
|
||||
// If we're exiting successfully, then return the global
|
||||
// exit status, which can be set programmatically.
|
||||
util::get_exit_status()
|
||||
} else {
|
||||
DEFAULT_ERROR_CODE
|
||||
};
|
||||
(*exit_code_clone.get()).store(exit_code, SeqCst);
|
||||
}
|
||||
};
|
||||
|
@ -97,3 +97,25 @@ memory and partly incapable of presentation to others.",
|
||||
|
||||
unsafe { libc::abort(); }
|
||||
}
|
||||
|
||||
pub fn set_exit_status(code: int) {
|
||||
|
||||
unsafe {
|
||||
return rust_set_exit_status_newrt(code as libc::uintptr_t);
|
||||
}
|
||||
|
||||
extern {
|
||||
fn rust_set_exit_status_newrt(code: libc::uintptr_t);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_exit_status() -> int {
|
||||
|
||||
unsafe {
|
||||
return rust_get_exit_status_newrt() as int;
|
||||
}
|
||||
|
||||
extern {
|
||||
fn rust_get_exit_status_newrt() -> libc::uintptr_t;
|
||||
}
|
||||
}
|
@ -960,6 +960,21 @@ rust_get_global_args_ptr() {
|
||||
return &global_args_ptr;
|
||||
}
|
||||
|
||||
static lock_and_signal exit_status_lock;
|
||||
static uintptr_t exit_status = 0;
|
||||
|
||||
extern "C" CDECL void
|
||||
rust_set_exit_status_newrt(uintptr_t code) {
|
||||
scoped_lock with(exit_status_lock);
|
||||
exit_status = code;
|
||||
}
|
||||
|
||||
extern "C" CDECL uintptr_t
|
||||
rust_get_exit_status_newrt() {
|
||||
scoped_lock with(exit_status_lock);
|
||||
return exit_status;
|
||||
}
|
||||
|
||||
//
|
||||
// Local Variables:
|
||||
// mode: C++
|
||||
|
@ -270,3 +270,5 @@ rust_get_global_args_ptr
|
||||
rust_current_boxed_region
|
||||
rust_take_global_args_lock
|
||||
rust_drop_global_args_lock
|
||||
rust_set_exit_status_newrt
|
||||
rust_get_exit_status_newrt
|
Loading…
x
Reference in New Issue
Block a user