diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-12-31 10:20:31 -0800 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-12-31 10:20:31 -0800 |
| commit | aec67c2ee0f673ea7b0e21c2fe7e0f26a523d823 (patch) | |
| tree | 032a8ec1398c7334c20b791a4c4c460feb5e2c79 /src/libstd/rt | |
| parent | 582cba183f18eea5c40b6c035d63ad449a9e8604 (diff) | |
| download | rust-aec67c2ee0f673ea7b0e21c2fe7e0f26a523d823.tar.gz rust-aec67c2ee0f673ea7b0e21c2fe7e0f26a523d823.zip | |
Revert "std: Re-enable at_exit()"
This reverts commit 9e224c2bf18ebf8f871efb2e1aba43ed7970ebb7. Conflicts: src/libstd/sys/windows/os.rs
Diffstat (limited to 'src/libstd/rt')
| -rw-r--r-- | src/libstd/rt/at_exit_imp.rs | 4 | ||||
| -rw-r--r-- | src/libstd/rt/mod.rs | 25 | ||||
| -rw-r--r-- | src/libstd/rt/unwind.rs | 17 |
3 files changed, 23 insertions, 23 deletions
diff --git a/src/libstd/rt/at_exit_imp.rs b/src/libstd/rt/at_exit_imp.rs index 08dabd3b0b6..5823f8453d8 100644 --- a/src/libstd/rt/at_exit_imp.rs +++ b/src/libstd/rt/at_exit_imp.rs @@ -29,8 +29,6 @@ type Queue = Vec<Thunk>; static LOCK: Mutex = MUTEX_INIT; static mut QUEUE: *mut Queue = 0 as *mut Queue; -const DTOR_RUN_ITERS: uint = 10; - unsafe fn init() { if QUEUE.is_null() { let state: Box<Queue> = box Vec::new(); @@ -51,7 +49,7 @@ pub fn cleanup() { unsafe { LOCK.lock(); let queue = QUEUE; - QUEUE = 1u as *mut _; + QUEUE = 1 as *mut _; LOCK.unlock(); // make sure we're not recursively cleaning up diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index a4421f23c50..e877dd5c6aa 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -92,7 +92,9 @@ fn lang_start(main: *const u8, argc: int, argv: *const *const u8) -> int { // but we just do this to name the main thread and to give it correct // info about the stack bounds. let thread: Thread = NewThread::new(Some("<main>".to_string())); - thread_info::set(sys::thread::guard::main(), thread); + thread_info::set((my_stack_bottom, my_stack_top), + sys::thread::guard::main(), + thread); // By default, some platforms will send a *signal* when a EPIPE error // would otherwise be delivered. This runtime doesn't install a SIGPIPE @@ -131,14 +133,20 @@ fn lang_start(main: *const u8, argc: int, argv: *const *const u8) -> int { } } -/// Enqueues a procedure to run when the main thread exits. +/// Enqueues a procedure to run when the runtime is cleaned up +/// +/// The procedure passed to this function will be executed as part of the +/// runtime cleanup phase. For normal rust programs, this means that it will run +/// after all other threads have exited. +/// +/// The procedure is *not* executed with a local `Thread` available to it, so +/// primitives like logging, I/O, channels, spawning, etc, are *not* available. +/// This is meant for "bare bones" usage to clean up runtime details, this is +/// not meant as a general-purpose "let's clean everything up" function. /// /// It is forbidden for procedures to register more `at_exit` handlers when they /// are running, and doing so will lead to a process abort. -/// -/// Note that other threads may still be running when `at_exit` routines start -/// running. -pub fn at_exit<F: FnOnce() + Send>(f: F) { +pub fn at_exit<F:FnOnce()+Send>(f: F) { at_exit_imp::push(Thunk::new(f)); } @@ -154,5 +162,8 @@ pub fn at_exit<F: FnOnce() + Send>(f: F) { pub unsafe fn cleanup() { args::cleanup(); sys::stack_overflow::cleanup(); - at_exit_imp::cleanup(); + // FIXME: (#20012): the resources being cleaned up by at_exit + // currently are not prepared for cleanup to happen asynchronously + // with detached threads using the resources; for now, we leak. + // at_exit_imp::cleanup(); } diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs index ce284e020a6..c273c52dacc 100644 --- a/src/libstd/rt/unwind.rs +++ b/src/libstd/rt/unwind.rs @@ -68,7 +68,7 @@ use intrinsics; use libc::c_void; use mem; use sync::atomic; -use sys_common::mutex::{Mutex, MUTEX_INIT}; +use sync::{Once, ONCE_INIT}; use rt::libunwind as uw; @@ -540,20 +540,11 @@ pub fn begin_unwind<M: Any + Send>(msg: M, file_line: &(&'static str, uint)) -> /// Doing this split took the LLVM IR line counts of `fn main() { panic!() /// }` from ~1900/3700 (-O/no opts) to 180/590. #[inline(never)] #[cold] // this is the slow path, please never inline this -fn begin_unwind_inner(msg: Box<Any + Send>, - file_line: &(&'static str, uint)) -> ! { +fn begin_unwind_inner(msg: Box<Any + Send>, file_line: &(&'static str, uint)) -> ! { // Make sure the default failure handler is registered before we look at the // callbacks. - unsafe { - static LOCK: Mutex = MUTEX_INIT; - static mut INIT: bool = false; - LOCK.lock(); - if !INIT { - register(failure::on_fail); - INIT = true; - } - LOCK.unlock(); - } + static INIT: Once = ONCE_INIT; + INIT.doit(|| unsafe { register(failure::on_fail); }); // First, invoke call the user-defined callbacks triggered on thread panic. // |
