@@ -9,7 +9,7 @@ use crate::cell::RefCell;
9
9
use crate :: fmt;
10
10
use crate :: io:: { self , BufReader , Initializer , IoSlice , IoSliceMut , LineWriter } ;
11
11
use crate :: lazy:: SyncOnceCell ;
12
- use crate :: sync:: { Arc , Mutex , MutexGuard } ;
12
+ use crate :: sync:: { Mutex , MutexGuard } ;
13
13
use crate :: sys:: stdio;
14
14
use crate :: sys_common;
15
15
use crate :: sys_common:: remutex:: { ReentrantMutex , ReentrantMutexGuard } ;
@@ -218,7 +218,7 @@ fn handle_ebadf<T>(r: io::Result<T>, default: T) -> io::Result<T> {
218
218
/// ```
219
219
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
220
220
pub struct Stdin {
221
- inner : Arc < Mutex < BufReader < StdinRaw > > > ,
221
+ inner : & ' static Mutex < BufReader < StdinRaw > > ,
222
222
}
223
223
224
224
/// A locked reference to the `Stdin` handle.
@@ -293,13 +293,11 @@ pub struct StdinLock<'a> {
293
293
/// ```
294
294
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
295
295
pub fn stdin ( ) -> Stdin {
296
- static INSTANCE : SyncOnceCell < Arc < Mutex < BufReader < StdinRaw > > > > = SyncOnceCell :: new ( ) ;
296
+ static INSTANCE : SyncOnceCell < Mutex < BufReader < StdinRaw > > > = SyncOnceCell :: new ( ) ;
297
297
Stdin {
298
- inner : INSTANCE
299
- . get_or_init ( || {
300
- Arc :: new ( Mutex :: new ( BufReader :: with_capacity ( stdio:: STDIN_BUF_SIZE , stdin_raw ( ) ) ) )
301
- } )
302
- . clone ( ) ,
298
+ inner : INSTANCE . get_or_init ( || {
299
+ Mutex :: new ( BufReader :: with_capacity ( stdio:: STDIN_BUF_SIZE , stdin_raw ( ) ) )
300
+ } ) ,
303
301
}
304
302
}
305
303
@@ -475,7 +473,7 @@ pub struct Stdout {
475
473
// FIXME: this should be LineWriter or BufWriter depending on the state of
476
474
// stdout (tty or not). Note that if this is not line buffered it
477
475
// should also flush-on-panic or some form of flush-on-abort.
478
- inner : Arc < ReentrantMutex < RefCell < LineWriter < StdoutRaw > > > > ,
476
+ inner : & ' static ReentrantMutex < RefCell < LineWriter < StdoutRaw > > > ,
479
477
}
480
478
481
479
/// A locked reference to the `Stdout` handle.
@@ -533,27 +531,25 @@ pub struct StdoutLock<'a> {
533
531
/// ```
534
532
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
535
533
pub fn stdout ( ) -> Stdout {
536
- static INSTANCE : SyncOnceCell < Arc < ReentrantMutex < RefCell < LineWriter < StdoutRaw > > > > > =
534
+ static INSTANCE : SyncOnceCell < ReentrantMutex < RefCell < LineWriter < StdoutRaw > > > > =
537
535
SyncOnceCell :: new ( ) ;
538
536
Stdout {
539
- inner : INSTANCE
540
- . get_or_init ( || unsafe {
541
- let _ = sys_common:: at_exit ( || {
542
- if let Some ( instance) = INSTANCE . get ( ) {
543
- // Flush the data and disable buffering during shutdown
544
- // by replacing the line writer by one with zero
545
- // buffering capacity.
546
- // We use try_lock() instead of lock(), because someone
547
- // might have leaked a StdoutLock, which would
548
- // otherwise cause a deadlock here.
549
- if let Some ( lock) = instance. try_lock ( ) {
550
- * lock. borrow_mut ( ) = LineWriter :: with_capacity ( 0 , stdout_raw ( ) ) ;
551
- }
537
+ inner : INSTANCE . get_or_init ( || unsafe {
538
+ let _ = sys_common:: at_exit ( || {
539
+ if let Some ( instance) = INSTANCE . get ( ) {
540
+ // Flush the data and disable buffering during shutdown
541
+ // by replacing the line writer by one with zero
542
+ // buffering capacity.
543
+ // We use try_lock() instead of lock(), because someone
544
+ // might have leaked a StdoutLock, which would
545
+ // otherwise cause a deadlock here.
546
+ if let Some ( lock) = instance. try_lock ( ) {
547
+ * lock. borrow_mut ( ) = LineWriter :: with_capacity ( 0 , stdout_raw ( ) ) ;
552
548
}
553
- } ) ;
554
- Arc :: new ( ReentrantMutex :: new ( RefCell :: new ( LineWriter :: new ( stdout_raw ( ) ) ) ) )
555
- } )
556
- . clone ( ) ,
549
+ }
550
+ } ) ;
551
+ ReentrantMutex :: new ( RefCell :: new ( LineWriter :: new ( stdout_raw ( ) ) ) )
552
+ } ) ,
557
553
}
558
554
}
559
555
0 commit comments