28
28
29
29
#[ allow( missing_doc) ] ;
30
30
31
- #[ cfg( unix) ]
32
- use c_str:: CString ;
33
31
use clone:: Clone ;
34
32
use container:: Container ;
35
33
#[ cfg( target_os = "macos" ) ]
@@ -43,6 +41,7 @@ use ptr;
43
41
use str;
44
42
use to_str;
45
43
use unstable:: finally:: Finally ;
44
+ use sync:: atomics:: { AtomicInt , INIT_ATOMIC_INT , SeqCst } ;
46
45
47
46
pub use os:: consts:: * ;
48
47
@@ -58,6 +57,8 @@ static BUF_BYTES : uint = 2048u;
58
57
59
58
#[ cfg( unix) ]
60
59
pub fn getcwd ( ) -> Path {
60
+ use c_str:: CString ;
61
+
61
62
let mut buf = [ 0 as libc:: c_char , ..BUF_BYTES ] ;
62
63
unsafe {
63
64
if libc:: getcwd ( buf. as_mut_ptr ( ) , buf. len ( ) as size_t ) . is_null ( ) {
@@ -675,17 +676,26 @@ pub fn last_os_error() -> ~str {
675
676
strerror ( )
676
677
}
677
678
679
+ static mut EXIT_STATUS : AtomicInt = INIT_ATOMIC_INT ;
680
+
678
681
/**
679
682
* Sets the process exit code
680
683
*
681
684
* Sets the exit code returned by the process if all supervised tasks
682
685
* terminate successfully (without failing). If the current root task fails
683
686
* and is supervised by the scheduler then any user-specified exit status is
684
- * ignored and the process exits with the default failure status
687
+ * ignored and the process exits with the default failure status.
688
+ *
689
+ * Note that this is not synchronized against modifications of other threads.
685
690
*/
686
691
pub fn set_exit_status ( code : int ) {
687
- use rt;
688
- rt:: set_exit_status ( code) ;
692
+ unsafe { EXIT_STATUS . store ( code, SeqCst ) }
693
+ }
694
+
695
+ /// Fetches the process's current exit code. This defaults to 0 and can change
696
+ /// by calling `set_exit_status`.
697
+ pub fn get_exit_status ( ) -> int {
698
+ unsafe { EXIT_STATUS . load ( SeqCst ) }
689
699
}
690
700
691
701
#[ cfg( target_os = "macos" ) ]
0 commit comments