summary refs log tree commit diff
path: root/src/libstd/io
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-12-31 10:20:31 -0800
committerAlex Crichton <alex@alexcrichton.com>2014-12-31 10:20:31 -0800
commitaec67c2ee0f673ea7b0e21c2fe7e0f26a523d823 (patch)
tree032a8ec1398c7334c20b791a4c4c460feb5e2c79 /src/libstd/io
parent582cba183f18eea5c40b6c035d63ad449a9e8604 (diff)
downloadrust-aec67c2ee0f673ea7b0e21c2fe7e0f26a523d823.tar.gz
rust-aec67c2ee0f673ea7b0e21c2fe7e0f26a523d823.zip
Revert "std: Re-enable at_exit()"
This reverts commit 9e224c2bf18ebf8f871efb2e1aba43ed7970ebb7.

Conflicts:
	src/libstd/sys/windows/os.rs
Diffstat (limited to 'src/libstd/io')
-rw-r--r--src/libstd/io/stdio.rs43
1 files changed, 24 insertions, 19 deletions
diff --git a/src/libstd/io/stdio.rs b/src/libstd/io/stdio.rs
index d009b553501..43d2e078035 100644
--- a/src/libstd/io/stdio.rs
+++ b/src/libstd/io/stdio.rs
@@ -26,19 +26,29 @@
 //! ```
 
 use self::StdSource::*;
-use prelude::*;
 
+use boxed::Box;
 use cell::RefCell;
+use clone::Clone;
 use failure::LOCAL_STDERR;
 use fmt;
-use io::{IoResult, IoError, OtherIoError};
-use io::{standard_error, EndOfFile, LineBufferedWriter, BufferedReader};
+use io::{Reader, Writer, IoResult, IoError, OtherIoError, Buffer,
+         standard_error, EndOfFile, LineBufferedWriter, BufferedReader};
+use kinds::{Sync, Send};
 use libc;
 use mem;
+use option::Option;
+use option::Option::{Some, None};
+use ops::{Deref, DerefMut, FnOnce};
+use result::Result::{Ok, Err};
 use rt;
+use slice::SliceExt;
+use str::StrExt;
+use string::String;
 use sys::{fs, tty};
-use sync::{Arc, Mutex, MutexGuard, StaticMutex, MUTEX_INIT};
+use sync::{Arc, Mutex, MutexGuard, Once, ONCE_INIT};
 use uint;
+use vec::Vec;
 
 // And so begins the tale of acquiring a uv handle to a stdio stream on all
 // platforms in all situations. Our story begins by splitting the world into two
@@ -205,15 +215,14 @@ impl Reader for StdinReader {
 pub fn stdin() -> StdinReader {
     // We're following the same strategy as kimundi's lazy_static library
     static mut STDIN: *const StdinReader = 0 as *const StdinReader;
-    static LOCK: StaticMutex = MUTEX_INIT;
+    static ONCE: Once = ONCE_INIT;
 
     unsafe {
-        let _g = LOCK.lock();
-        if STDIN as uint == 0 {
-            // The default buffer capacity is 64k, but apparently windows
-            // doesn't like 64k reads on stdin. See #13304 for details, but the
-            // idea is that on windows we use a slightly smaller buffer that's
-            // been seen to be acceptable.
+        ONCE.doit(|| {
+            // The default buffer capacity is 64k, but apparently windows doesn't like
+            // 64k reads on stdin. See #13304 for details, but the idea is that on
+            // windows we use a slightly smaller buffer that's been seen to be
+            // acceptable.
             let stdin = if cfg!(windows) {
                 BufferedReader::with_capacity(8 * 1024, stdin_raw())
             } else {
@@ -226,15 +235,11 @@ pub fn stdin() -> StdinReader {
 
             // Make sure to free it at exit
             rt::at_exit(|| {
-                let g = LOCK.lock();
-                let stdin = STDIN;
-                STDIN = 1 as *const _;
-                drop(g);
-                mem::transmute::<_, Box<StdinReader>>(stdin);
+                mem::transmute::<_, Box<StdinReader>>(STDIN);
+                STDIN = 0 as *const _;
             });
-        } else if STDIN as uint == 1 {
-            panic!("accessing stdin after the main thread has exited")
-        }
+        });
+
         (*STDIN).clone()
     }
 }