@@ -9,8 +9,9 @@ use crate::cell::{Cell, RefCell};
9
9
use crate :: fmt;
10
10
use crate :: fs:: File ;
11
11
use crate :: io:: { self , BorrowedCursor , BufReader , IoSlice , IoSliceMut , LineWriter , Lines } ;
12
+ use crate :: panic:: { RefUnwindSafe , UnwindSafe } ;
12
13
use 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 } ;
14
15
use crate :: sys:: stdio;
15
16
16
17
type LocalStream = Arc < Mutex < Vec < u8 > > > ;
@@ -536,7 +537,7 @@ pub struct Stdout {
536
537
// FIXME: this should be LineWriter or BufWriter depending on the state of
537
538
// stdout (tty or not). Note that if this is not line buffered it
538
539
// 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 > > > ,
540
541
}
541
542
542
543
/// A locked reference to the [`Stdout`] handle.
@@ -558,10 +559,10 @@ pub struct Stdout {
558
559
#[ must_use = "if unused stdout will immediately unlock" ]
559
560
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
560
561
pub struct StdoutLock < ' a > {
561
- inner : ReentrantMutexGuard < ' a , RefCell < LineWriter < StdoutRaw > > > ,
562
+ inner : ReentrantLockGuard < ' a , RefCell < LineWriter < StdoutRaw > > > ,
562
563
}
563
564
564
- static STDOUT : OnceLock < ReentrantMutex < RefCell < LineWriter < StdoutRaw > > > > = OnceLock :: new ( ) ;
565
+ static STDOUT : OnceLock < ReentrantLock < RefCell < LineWriter < StdoutRaw > > > > = OnceLock :: new ( ) ;
565
566
566
567
/// Constructs a new handle to the standard output of the current process.
567
568
///
@@ -614,7 +615,7 @@ static STDOUT: OnceLock<ReentrantMutex<RefCell<LineWriter<StdoutRaw>>>> = OnceLo
614
615
pub fn stdout ( ) -> Stdout {
615
616
Stdout {
616
617
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 ( ) ) ) ) ) ,
618
619
}
619
620
}
620
621
@@ -625,7 +626,7 @@ pub fn cleanup() {
625
626
let mut initialized = false ;
626
627
let stdout = STDOUT . get_or_init ( || {
627
628
initialized = true ;
628
- ReentrantMutex :: new ( RefCell :: new ( LineWriter :: with_capacity ( 0 , stdout_raw ( ) ) ) )
629
+ ReentrantLock :: new ( RefCell :: new ( LineWriter :: with_capacity ( 0 , stdout_raw ( ) ) ) )
629
630
} ) ;
630
631
631
632
if !initialized {
@@ -668,6 +669,12 @@ impl Stdout {
668
669
}
669
670
}
670
671
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
+
671
678
#[ stable( feature = "std_debug" , since = "1.16.0" ) ]
672
679
impl fmt:: Debug for Stdout {
673
680
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -727,6 +734,12 @@ impl Write for &Stdout {
727
734
}
728
735
}
729
736
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
+
730
743
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
731
744
impl Write for StdoutLock < ' _ > {
732
745
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
@@ -776,7 +789,7 @@ impl fmt::Debug for StdoutLock<'_> {
776
789
/// standard library or via raw Windows API calls, will fail.
777
790
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
778
791
pub struct Stderr {
779
- inner : & ' static ReentrantMutex < RefCell < StderrRaw > > ,
792
+ inner : & ' static ReentrantLock < RefCell < StderrRaw > > ,
780
793
}
781
794
782
795
/// A locked reference to the [`Stderr`] handle.
@@ -798,7 +811,7 @@ pub struct Stderr {
798
811
#[ must_use = "if unused stderr will immediately unlock" ]
799
812
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
800
813
pub struct StderrLock < ' a > {
801
- inner : ReentrantMutexGuard < ' a , RefCell < StderrRaw > > ,
814
+ inner : ReentrantLockGuard < ' a , RefCell < StderrRaw > > ,
802
815
}
803
816
804
817
/// Constructs a new handle to the standard error of the current process.
@@ -851,8 +864,8 @@ pub fn stderr() -> Stderr {
851
864
// Note that unlike `stdout()` we don't use `at_exit` here to register a
852
865
// destructor. Stderr is not buffered, so there's no need to run a
853
866
// 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 ( ) ) ) ;
856
869
857
870
Stderr { inner : & INSTANCE }
858
871
}
@@ -887,6 +900,12 @@ impl Stderr {
887
900
}
888
901
}
889
902
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
+
890
909
#[ stable( feature = "std_debug" , since = "1.16.0" ) ]
891
910
impl fmt:: Debug for Stderr {
892
911
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
@@ -946,6 +965,12 @@ impl Write for &Stderr {
946
965
}
947
966
}
948
967
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
+
949
974
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
950
975
impl Write for StderrLock < ' _ > {
951
976
fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
0 commit comments