@@ -9,8 +9,9 @@ use crate::cell::{Cell, RefCell};
99use crate :: fmt;
1010use crate :: fs:: File ;
1111use crate :: io:: { self , BorrowedCursor , BufReader , IoSlice , IoSliceMut , LineWriter , Lines } ;
12+ use crate :: panic:: { RefUnwindSafe , UnwindSafe } ;
1213use crate :: sync:: atomic:: { AtomicBool , Ordering } ;
13- use crate :: sync:: { Arc , Mutex , MutexGuard , OnceLock , ReentrantMutex , ReentrantMutexGuard } ;
14+ use crate :: sync:: { Arc , Mutex , MutexGuard , OnceLock , ReentrantLock , ReentrantLockGuard } ;
1415use crate :: sys:: stdio;
1516
1617type LocalStream = Arc < Mutex < Vec < u8 > > > ;
@@ -536,7 +537,7 @@ pub struct Stdout {
536537 // FIXME: this should be LineWriter or BufWriter depending on the state of
537538 // stdout (tty or not). Note that if this is not line buffered it
538539 // should also flush-on-panic or some form of flush-on-abort.
539- inner : & ' static ReentrantMutex < RefCell < LineWriter < StdoutRaw > > > ,
540+ inner : & ' static ReentrantLock < RefCell < LineWriter < StdoutRaw > > > ,
540541}
541542
542543/// A locked reference to the [`Stdout`] handle.
@@ -558,10 +559,10 @@ pub struct Stdout {
558559#[ must_use = "if unused stdout will immediately unlock" ]
559560#[ stable( feature = "rust1" , since = "1.0.0" ) ]
560561pub struct StdoutLock < ' a > {
561- inner : ReentrantMutexGuard < ' a , RefCell < LineWriter < StdoutRaw > > > ,
562+ inner : ReentrantLockGuard < ' a , RefCell < LineWriter < StdoutRaw > > > ,
562563}
563564
564- static STDOUT : OnceLock < ReentrantMutex < RefCell < LineWriter < StdoutRaw > > > > = OnceLock :: new ( ) ;
565+ static STDOUT : OnceLock < ReentrantLock < RefCell < LineWriter < StdoutRaw > > > > = OnceLock :: new ( ) ;
565566
566567/// Constructs a new handle to the standard output of the current process.
567568///
@@ -614,7 +615,7 @@ static STDOUT: OnceLock<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> = OnceLo
614615pub fn stdout ( ) -> Stdout {
615616 Stdout {
616617 inner : STDOUT
617- . get_or_init ( || ReentrantMutex :: new ( RefCell :: new ( LineWriter :: new ( stdout_raw ( ) ) ) ) ) ,
618+ . get_or_init ( || ReentrantLock :: new ( RefCell :: new ( LineWriter :: new ( stdout_raw ( ) ) ) ) ) ,
618619 }
619620}
620621
@@ -625,7 +626,7 @@ pub fn cleanup() {
625626 let mut initialized = false ;
626627 let stdout = STDOUT . get_or_init ( || {
627628 initialized = true ;
628- ReentrantMutex :: new ( RefCell :: new ( LineWriter :: with_capacity ( 0 , stdout_raw ( ) ) ) )
629+ ReentrantLock :: new ( RefCell :: new ( LineWriter :: with_capacity ( 0 , stdout_raw ( ) ) ) )
629630 } ) ;
630631
631632 if !initialized {
@@ -668,6 +669,12 @@ impl Stdout {
668669 }
669670}
670671
672+ #[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
673+ impl UnwindSafe for Stdout { }
674+
675+ #[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
676+ impl RefUnwindSafe for Stdout { }
677+
671678#[ stable( feature = "std_debug" , since = "1.16.0" ) ]
672679impl fmt:: Debug for Stdout {
673680 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -727,6 +734,12 @@ impl Write for &Stdout {
727734 }
728735}
729736
737+ #[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
738+ impl UnwindSafe for StdoutLock < ' _ > { }
739+
740+ #[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
741+ impl RefUnwindSafe for StdoutLock < ' _ > { }
742+
730743#[ stable( feature = "rust1" , since = "1.0.0" ) ]
731744impl Write for StdoutLock < ' _ > {
732745 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
@@ -776,7 +789,7 @@ impl fmt::Debug for StdoutLock<'_> {
776789/// standard library or via raw Windows API calls, will fail.
777790#[ stable( feature = "rust1" , since = "1.0.0" ) ]
778791pub struct Stderr {
779- inner : & ' static ReentrantMutex < RefCell < StderrRaw > > ,
792+ inner : & ' static ReentrantLock < RefCell < StderrRaw > > ,
780793}
781794
782795/// A locked reference to the [`Stderr`] handle.
@@ -798,7 +811,7 @@ pub struct Stderr {
798811#[ must_use = "if unused stderr will immediately unlock" ]
799812#[ stable( feature = "rust1" , since = "1.0.0" ) ]
800813pub struct StderrLock < ' a > {
801- inner : ReentrantMutexGuard < ' a , RefCell < StderrRaw > > ,
814+ inner : ReentrantLockGuard < ' a , RefCell < StderrRaw > > ,
802815}
803816
804817/// Constructs a new handle to the standard error of the current process.
@@ -851,8 +864,8 @@ pub fn stderr() -> Stderr {
851864 // Note that unlike `stdout()` we don't use `at_exit` here to register a
852865 // destructor. Stderr is not buffered, so there's no need to run a
853866 // destructor for flushing the buffer
854- static INSTANCE : ReentrantMutex < RefCell < StderrRaw > > =
855- ReentrantMutex :: new ( RefCell :: new ( stderr_raw ( ) ) ) ;
867+ static INSTANCE : ReentrantLock < RefCell < StderrRaw > > =
868+ ReentrantLock :: new ( RefCell :: new ( stderr_raw ( ) ) ) ;
856869
857870 Stderr { inner : & INSTANCE }
858871}
@@ -887,6 +900,12 @@ impl Stderr {
887900 }
888901}
889902
903+ #[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
904+ impl UnwindSafe for Stderr { }
905+
906+ #[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
907+ impl RefUnwindSafe for Stderr { }
908+
890909#[ stable( feature = "std_debug" , since = "1.16.0" ) ]
891910impl fmt:: Debug for Stderr {
892911 fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -946,6 +965,12 @@ impl Write for &Stderr {
946965 }
947966}
948967
968+ #[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
969+ impl UnwindSafe for StderrLock < ' _ > { }
970+
971+ #[ stable( feature = "catch_unwind" , since = "1.9.0" ) ]
972+ impl RefUnwindSafe for StderrLock < ' _ > { }
973+
949974#[ stable( feature = "rust1" , since = "1.0.0" ) ]
950975impl Write for StderrLock < ' _ > {
951976 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
0 commit comments