@@ -11,8 +11,9 @@ use crate::fs::File;
11
11
use crate :: io:: {
12
12
self , BorrowedCursor , BufReader , IoSlice , IoSliceMut , LineWriter , Lines , SpecReadByte ,
13
13
} ;
14
+ use crate :: panic:: { RefUnwindSafe , UnwindSafe } ;
14
15
use 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 } ;
16
17
use crate :: sys:: stdio;
17
18
18
19
type LocalStream = Arc < Mutex < Vec < u8 > > > ;
@@ -545,7 +546,7 @@ pub struct Stdout {
545
546
// FIXME: this should be LineWriter or BufWriter depending on the state of
546
547
// stdout (tty or not). Note that if this is not line buffered it
547
548
// 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 > > > ,
549
550
}
550
551
551
552
/// A locked reference to the [`Stdout`] handle.
@@ -567,10 +568,10 @@ pub struct Stdout {
567
568
#[ must_use = "if unused stdout will immediately unlock" ]
568
569
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
569
570
pub struct StdoutLock < ' a > {
570
- inner : ReentrantMutexGuard < ' a , RefCell < LineWriter < StdoutRaw > > > ,
571
+ inner : ReentrantLockGuard < ' a , RefCell < LineWriter < StdoutRaw > > > ,
571
572
}
572
573
573
- static STDOUT : OnceLock < ReentrantMutex < RefCell < LineWriter < StdoutRaw > > > > = OnceLock :: new ( ) ;
574
+ static STDOUT : OnceLock < ReentrantLock < RefCell < LineWriter < StdoutRaw > > > > = OnceLock :: new ( ) ;
574
575
575
576
/// Constructs a new handle to the standard output of the current process.
576
577
///
@@ -624,7 +625,7 @@ static STDOUT: OnceLock<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> = OnceLo
624
625
pub fn stdout ( ) -> Stdout {
625
626
Stdout {
626
627
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 ( ) ) ) ) ) ,
628
629
}
629
630
}
630
631
@@ -635,7 +636,7 @@ pub fn cleanup() {
635
636
let mut initialized = false ;
636
637
let stdout = STDOUT . get_or_init ( || {
637
638
initialized = true ;
638
- ReentrantMutex :: new ( RefCell :: new ( LineWriter :: with_capacity ( 0 , stdout_raw ( ) ) ) )
639
+ ReentrantLock :: new ( RefCell :: new ( LineWriter :: with_capacity ( 0 , stdout_raw ( ) ) ) )
639
640
} ) ;
640
641
641
642
if !initialized {
@@ -678,6 +679,12 @@ impl Stdout {
678
679
}
679
680
}
680
681
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
+
681
688
#[ stable( feature = "std_debug" , since = "1.16.0" ) ]
682
689
impl fmt:: Debug for Stdout {
683
690
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -737,6 +744,12 @@ impl Write for &Stdout {
737
744
}
738
745
}
739
746
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
+
740
753
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
741
754
impl Write for StdoutLock < ' _ > {
742
755
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
@@ -786,7 +799,7 @@ impl fmt::Debug for StdoutLock<'_> {
786
799
/// standard library or via raw Windows API calls, will fail.
787
800
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
788
801
pub struct Stderr {
789
- inner : & ' static ReentrantMutex < RefCell < StderrRaw > > ,
802
+ inner : & ' static ReentrantLock < RefCell < StderrRaw > > ,
790
803
}
791
804
792
805
/// A locked reference to the [`Stderr`] handle.
@@ -808,7 +821,7 @@ pub struct Stderr {
808
821
#[ must_use = "if unused stderr will immediately unlock" ]
809
822
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
810
823
pub struct StderrLock < ' a > {
811
- inner : ReentrantMutexGuard < ' a , RefCell < StderrRaw > > ,
824
+ inner : ReentrantLockGuard < ' a , RefCell < StderrRaw > > ,
812
825
}
813
826
814
827
/// Constructs a new handle to the standard error of the current process.
@@ -862,8 +875,8 @@ pub fn stderr() -> Stderr {
862
875
// Note that unlike `stdout()` we don't use `at_exit` here to register a
863
876
// destructor. Stderr is not buffered, so there's no need to run a
864
877
// 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 ( ) ) ) ;
867
880
868
881
Stderr { inner : & INSTANCE }
869
882
}
@@ -898,6 +911,12 @@ impl Stderr {
898
911
}
899
912
}
900
913
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
+
901
920
#[ stable( feature = "std_debug" , since = "1.16.0" ) ]
902
921
impl fmt:: Debug for Stderr {
903
922
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -957,6 +976,12 @@ impl Write for &Stderr {
957
976
}
958
977
}
959
978
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
+
960
985
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
961
986
impl Write for StderrLock < ' _ > {
962
987
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
0 commit comments