about summary refs log tree commit diff
path: root/src/libstd/sys/common/mod.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2015-09-08 15:53:46 -0700
committerAlex Crichton <alex@alexcrichton.com>2015-09-11 11:19:20 -0700
commitf4be2026dfb507e5db919cc5df8fd934e05fa0b8 (patch)
tree278d5b3916042e7232b7ba98a5ead399a52057eb /src/libstd/sys/common/mod.rs
parent192c37537bc6ffaee06e8b4099dd09ae43bcfee7 (diff)
std: Internalize almost all of `std::rt`
This commit does some refactoring to make almost all of the `std::rt` private.
Specifically, the following items are no longer part of its API:

* DEFAULT_ERROR_CODE
* backtrace
* unwind
* args
* at_exit
* cleanup
* heap (this is just alloc::heap)
* min_stack
* util

The module is now tagged as `#[doc(hidden)]` as the only purpose it's serve is
an entry point for the `panic!` macro via the `begin_unwind` and
`begin_unwind_fmt` reexports.
Diffstat (limited to 'src/libstd/sys/common/mod.rs')
-rw-r--r--src/libstd/sys/common/mod.rs48
1 files changed, 47 insertions, 1 deletions
diff --git a/src/libstd/sys/common/mod.rs b/src/libstd/sys/common/mod.rs
index b8074235fb2..44c55d1e2c4 100644
--- a/src/libstd/sys/common/mod.rs
+++ b/src/libstd/sys/common/mod.rs
@@ -10,17 +10,39 @@
 
 #![allow(missing_docs)]
 
+use boxed::Box;
+use sync::Once;
+use sys;
+
+macro_rules! rtabort {
+    ($($t:tt)*) => (::sys_common::util::abort(format_args!($($t)*)))
+}
+
+macro_rules! rtassert {
+    ($e:expr) => ({
+        if !$e {
+            rtabort!(concat!("assertion failed: ", stringify!($e)))
+        }
+    })
+}
+
+pub mod args;
+pub mod at_exit_imp;
 pub mod backtrace;
 pub mod condvar;
+pub mod dwarf;
+pub mod io;
+pub mod libunwind;
 pub mod mutex;
 pub mod net;
-pub mod io;
 pub mod poison;
 pub mod remutex;
 pub mod rwlock;
 pub mod thread;
 pub mod thread_info;
 pub mod thread_local;
+pub mod unwind;
+pub mod util;
 pub mod wtf8;
 
 #[cfg(any(all(unix, not(any(target_os = "macos", target_os = "ios"))),
@@ -52,3 +74,27 @@ pub trait IntoInner<Inner> {
 pub trait FromInner<Inner> {
     fn from_inner(inner: Inner) -> Self;
 }
+
+/// Enqueues a procedure to run when the main thread exits.
+///
+/// Currently these closures are only run once the main *Rust* thread exits.
+/// Once the `at_exit` handlers begin running, more may be enqueued, but not
+/// infinitely so. Eventually a handler registration will be forced to fail.
+///
+/// Returns `Ok` if the handler was successfully registered, meaning that the
+/// closure will be run once the main thread exits. Returns `Err` to indicate
+/// that the closure could not be registered, meaning that it is not scheduled
+/// to be run.
+pub fn at_exit<F: FnOnce() + Send + 'static>(f: F) -> Result<(), ()> {
+    if at_exit_imp::push(Box::new(f)) {Ok(())} else {Err(())}
+}
+
+/// One-time runtime cleanup.
+pub fn cleanup() {
+    static CLEANUP: Once = Once::new();
+    CLEANUP.call_once(|| unsafe {
+        args::cleanup();
+        sys::stack_overflow::cleanup();
+        at_exit_imp::cleanup();
+    });
+}