about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-12-12 17:51:54 -0800
committerAlex Crichton <alex@alexcrichton.com>2013-12-24 14:42:00 -0800
commitdaaec28c6f71f5d6e2f5bc716ffc2780ef56fa7b (patch)
tree91464a4a2283aaf580ff102ffebf074ff78ec23e /src/libstd
parent429313de69cb2ddd1f076017968d1862ef02b455 (diff)
downloadrust-daaec28c6f71f5d6e2f5bc716ffc2780ef56fa7b.tar.gz
rust-daaec28c6f71f5d6e2f5bc716ffc2780ef56fa7b.zip
std: Move management of the exit code to std::os
Previously this functionality was located in std::rt::util, but there's no real
reason for it to be located in there.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/os.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/src/libstd/os.rs b/src/libstd/os.rs
index 8da7c0340f7..43a9390bfb6 100644
--- a/src/libstd/os.rs
+++ b/src/libstd/os.rs
@@ -28,8 +28,6 @@
 
 #[allow(missing_doc)];
 
-#[cfg(unix)]
-use c_str::CString;
 use clone::Clone;
 use container::Container;
 #[cfg(target_os = "macos")]
@@ -43,6 +41,7 @@ use ptr;
 use str;
 use to_str;
 use unstable::finally::Finally;
+use sync::atomics::{AtomicInt, INIT_ATOMIC_INT, SeqCst};
 
 pub use os::consts::*;
 
@@ -58,6 +57,8 @@ static BUF_BYTES : uint = 2048u;
 
 #[cfg(unix)]
 pub fn getcwd() -> Path {
+    use c_str::CString;
+
     let mut buf = [0 as libc::c_char, ..BUF_BYTES];
     unsafe {
         if libc::getcwd(buf.as_mut_ptr(), buf.len() as size_t).is_null() {
@@ -675,17 +676,26 @@ pub fn last_os_error() -> ~str {
     strerror()
 }
 
+static mut EXIT_STATUS: AtomicInt = INIT_ATOMIC_INT;
+
 /**
  * Sets the process exit code
  *
  * Sets the exit code returned by the process if all supervised tasks
  * terminate successfully (without failing). If the current root task fails
  * and is supervised by the scheduler then any user-specified exit status is
- * ignored and the process exits with the default failure status
+ * ignored and the process exits with the default failure status.
+ *
+ * Note that this is not synchronized against modifications of other threads.
  */
 pub fn set_exit_status(code: int) {
-    use rt;
-    rt::set_exit_status(code);
+    unsafe { EXIT_STATUS.store(code, SeqCst) }
+}
+
+/// Fetches the process's current exit code. This defaults to 0 and can change
+/// by calling `set_exit_status`.
+pub fn get_exit_status() -> int {
+    unsafe { EXIT_STATUS.load(SeqCst) }
 }
 
 #[cfg(target_os = "macos")]