From aec67c2ee0f673ea7b0e21c2fe7e0f26a523d823 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 31 Dec 2014 10:20:31 -0800 Subject: Revert "std: Re-enable at_exit()" This reverts commit 9e224c2bf18ebf8f871efb2e1aba43ed7970ebb7. Conflicts: src/libstd/sys/windows/os.rs --- src/libstd/io/stdio.rs | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'src/libstd/io') 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>(stdin); + mem::transmute::<_, Box>(STDIN); + STDIN = 0 as *const _; }); - } else if STDIN as uint == 1 { - panic!("accessing stdin after the main thread has exited") - } + }); + (*STDIN).clone() } } -- cgit 1.4.1-3-g733a5