diff options
Diffstat (limited to 'ctr-std/src/sys_common/mod.rs')
| -rw-r--r-- | ctr-std/src/sys_common/mod.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/ctr-std/src/sys_common/mod.rs b/ctr-std/src/sys_common/mod.rs index c6f94ed..7aedb69 100644 --- a/ctr-std/src/sys_common/mod.rs +++ b/ctr-std/src/sys_common/mod.rs @@ -24,6 +24,7 @@ #![allow(missing_docs)] +pub mod at_exit_imp; pub mod io; pub mod mutex; pub mod poison; @@ -56,6 +57,20 @@ 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(())} +} + macro_rules! rtabort { ($($t:tt)*) => (::sys_common::util::abort(format_args!($($t)*))) } |