From 3f2366df139e8bc0323ab7ae287ffc9e25129c6c Mon Sep 17 00:00:00 2001 From: Fenrir Date: Fri, 24 Feb 2017 01:22:17 -0700 Subject: implement buffered stdio --- ctr-std/src/sys_common/mod.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'ctr-std/src/sys_common/mod.rs') 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 { 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: 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)*))) } -- cgit v1.2.3