@@ -11,8 +11,9 @@ use crate::fs::File;
1111use crate :: io:: {
1212 self , BorrowedCursor , BufReader , IoSlice , IoSliceMut , LineWriter , Lines , SpecReadByte ,
1313} ;
14+ use crate :: panic:: { RefUnwindSafe , UnwindSafe } ;
1415use crate :: sync:: atomic:: { AtomicBool , Ordering } ;
15- use crate :: sync:: { Arc , Mutex , MutexGuard , OnceLock , ReentrantMutex , ReentrantMutexGuard } ;
16+ use crate :: sync:: { Arc , Mutex , MutexGuard , OnceLock , ReentrantLock , ReentrantLockGuard } ;
1617use crate :: sys:: stdio;
1718
1819type LocalStream = Arc < Mutex < Vec < u8 > > > ;
@@ -545,7 +546,7 @@ pub struct Stdout {
545546 // FIXME: this should be LineWriter or BufWriter depending on the state of
546547 // stdout (tty or not). Note that if this is not line buffered it
547548 // should also flush-on-panic or some form of flush-on-abort.
548- inner : & ' static ReentrantMutex < RefCell < LineWriter < StdoutRaw > > > ,
549+ inner : & ' static ReentrantLock < RefCell < LineWriter < StdoutRaw > > > ,
549550}
550551
551552/// A locked reference to the [`Stdout`] handle.
@@ -567,10 +568,10 @@ pub struct Stdout {
567568#[ must_use = "if unused stdout will immediately unlock" ]
568569#[ stable( feature = "rust1" , since = "1.0.0" ) ]
569570pub struct StdoutLock < ' a > {
570- inner : ReentrantMutexGuard < ' a , RefCell < LineWriter < StdoutRaw > > > ,
571+ inner : ReentrantLockGuard < ' a , RefCell < LineWriter < StdoutRaw > > > ,
571572}
572573
573- static STDOUT : OnceLock < ReentrantMutex < RefCell < LineWriter < StdoutRaw > > > > = OnceLock :: new ( ) ;
574+ static STDOUT : OnceLock < ReentrantLock < RefCell < LineWriter < StdoutRaw > > > > = OnceLock :: new ( ) ;
574575
575576/// Constructs a new handle to the standard output of the current process.
576577///
@@ -624,7 +625,7 @@ static STDOUT: OnceLock<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> = OnceLo
624625pub fn stdout ( ) -> Stdout {
625626 Stdout {
626627 inner : STDOUT
627- . get_or_init ( || ReentrantMutex :: new ( RefCell :: new ( LineWriter :: new ( stdout_raw ( ) ) ) ) ) ,
628+ . get_or_init ( || ReentrantLock :: new ( RefCell :: new ( LineWriter :: new ( stdout_raw ( ) ) ) ) ) ,
628629 }
629630}
630631
@@ -635,7 +636,7 @@ pub fn cleanup() {
635636 let mut initialized = false ;
636637 let stdout = STDOUT . get_or_init ( || {
637638 initialized = true ;
638- ReentrantMutex :: new ( RefCell :: new ( LineWriter :: with_capacity ( 0 , stdout_raw ( ) ) ) )
639+ ReentrantLock :: new ( RefCell :: new ( LineWriter :: with_capacity ( 0 , stdout_raw ( ) ) ) )
639640 } ) ;
640641
641642 if !initialized {
@@ -678,6 +679,12 @@ impl Stdout {
678679 }
679680}
680681
682+ #[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
683+ impl UnwindSafe for Stdout { }
684+
685+ #[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
686+ impl RefUnwindSafe for Stdout { }
687+
681688#[ stable( feature = "std_debug" , since = "1.16.0" ) ]
682689impl fmt:: Debug for Stdout {
683690 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -737,6 +744,12 @@ impl Write for &Stdout {
737744 }
738745}
739746
747+ #[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
748+ impl UnwindSafe for StdoutLock < ' _ > { }
749+
750+ #[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
751+ impl RefUnwindSafe for StdoutLock < ' _ > { }
752+
740753#[ stable( feature = "rust1" , since = "1.0.0" ) ]
741754impl Write for StdoutLock < ' _ > {
742755 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
@@ -786,7 +799,7 @@ impl fmt::Debug for StdoutLock<'_> {
786799/// standard library or via raw Windows API calls, will fail.
787800#[ stable( feature = "rust1" , since = "1.0.0" ) ]
788801pub struct Stderr {
789- inner : & ' static ReentrantMutex < RefCell < StderrRaw > > ,
802+ inner : & ' static ReentrantLock < RefCell < StderrRaw > > ,
790803}
791804
792805/// A locked reference to the [`Stderr`] handle.
@@ -808,7 +821,7 @@ pub struct Stderr {
808821#[ must_use = "if unused stderr will immediately unlock" ]
809822#[ stable( feature = "rust1" , since = "1.0.0" ) ]
810823pub struct StderrLock < ' a > {
811- inner : ReentrantMutexGuard < ' a , RefCell < StderrRaw > > ,
824+ inner : ReentrantLockGuard < ' a , RefCell < StderrRaw > > ,
812825}
813826
814827/// Constructs a new handle to the standard error of the current process.
@@ -862,8 +875,8 @@ pub fn stderr() -> Stderr {
862875 // Note that unlike `stdout()` we don't use `at_exit` here to register a
863876 // destructor. Stderr is not buffered, so there's no need to run a
864877 // destructor for flushing the buffer
865- static INSTANCE : ReentrantMutex < RefCell < StderrRaw > > =
866- ReentrantMutex :: new ( RefCell :: new ( stderr_raw ( ) ) ) ;
878+ static INSTANCE : ReentrantLock < RefCell < StderrRaw > > =
879+ ReentrantLock :: new ( RefCell :: new ( stderr_raw ( ) ) ) ;
867880
868881 Stderr { inner : & INSTANCE }
869882}
@@ -898,6 +911,12 @@ impl Stderr {
898911 }
899912}
900913
914+ #[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
915+ impl UnwindSafe for Stderr { }
916+
917+ #[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
918+ impl RefUnwindSafe for Stderr { }
919+
901920#[ stable( feature = "std_debug" , since = "1.16.0" ) ]
902921impl fmt:: Debug for Stderr {
903922 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -957,6 +976,12 @@ impl Write for &Stderr {
957976 }
958977}
959978
979+ #[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
980+ impl UnwindSafe for StderrLock < ' _ > { }
981+
982+ #[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
983+ impl RefUnwindSafe for StderrLock < ' _ > { }
984+
960985#[ stable( feature = "rust1" , since = "1.0.0" ) ]
961986impl Write for StderrLock < ' _ > {
962987 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
0 commit comments