diff options
| author | Ronald Kinard <[email protected]> | 2017-02-25 21:19:47 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2017-02-25 21:19:47 -0600 |
| commit | 4ecade8af14dff869c4d41dcd60040b69f06b64e (patch) | |
| tree | 0bfc16fd5a5e1b5698e0fe9b786caf9a0c4062ae /ctr-std/src/sys_common/mod.rs | |
| parent | Merge pull request #23 from panicbit/unmarked_api (diff) | |
| parent | implement buffered stdio (diff) | |
| download | ctru-rs-4ecade8af14dff869c4d41dcd60040b69f06b64e.tar.xz ctru-rs-4ecade8af14dff869c4d41dcd60040b69f06b64e.zip | |
Merge pull request #22 from FenrirWolf/stdio
Implement synchronized stdio
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)*))) } |