@@ -61,32 +61,37 @@ mod mode {
6161 use std:: sync:: atomic:: AtomicU8 ;
6262
6363 const UNINITIALIZED : u8 = 0 ;
64- const INACTIVE : u8 = 1 ;
65- const ACTIVE : u8 = 2 ;
64+ const DYN_NOT_SYNC : u8 = 1 ;
65+ const DYN_SYNC : u8 = 2 ;
6666
67- static MODE : AtomicU8 = AtomicU8 :: new ( UNINITIALIZED ) ;
67+ static DYN_SYNC_MODE : AtomicU8 = AtomicU8 :: new ( UNINITIALIZED ) ;
6868
69+ // Weather control thread safety dynamically
6970 #[ inline]
70- pub fn active ( ) -> bool {
71- match MODE . load ( Ordering :: Relaxed ) {
72- INACTIVE => false ,
73- ACTIVE => true ,
71+ pub fn is_dyn_thread_safe ( ) -> bool {
72+ match DYN_SYNC_MODE . load ( Ordering :: Relaxed ) {
73+ DYN_NOT_SYNC => false ,
74+ DYN_SYNC => true ,
7475 _ => panic ! ( "uninitialized parallel mode!" ) ,
7576 }
7677 }
7778
7879 // Only set by the `-Z threads` compile option
79- pub fn set ( parallel : bool ) {
80- let set: u8 = if parallel { ACTIVE } else { INACTIVE } ;
81- let previous =
82- MODE . compare_exchange ( UNINITIALIZED , set, Ordering :: Relaxed , Ordering :: Relaxed ) ;
80+ pub fn set_dyn_thread_safe_mode ( parallel : bool ) {
81+ let set: u8 = if parallel { DYN_SYNC } else { DYN_NOT_SYNC } ;
82+ let previous = DYN_SYNC_MODE . compare_exchange (
83+ UNINITIALIZED ,
84+ set,
85+ Ordering :: Relaxed ,
86+ Ordering :: Relaxed ,
87+ ) ;
8388
8489 // Check that the mode was either uninitialized or was already set to the requested mode.
8590 assert ! ( previous. is_ok( ) || previous == Err ( set) ) ;
8691 }
8792}
8893
89- pub use mode:: { active , set } ;
94+ pub use mode:: { is_dyn_thread_safe , set_dyn_thread_safe_mode } ;
9095cfg_if ! {
9196 if #[ cfg( not( parallel_compiler) ) ] {
9297 pub unsafe auto trait Send { }
@@ -358,7 +363,7 @@ cfg_if! {
358363 A : FnOnce ( ) -> RA + DynSend ,
359364 B : FnOnce ( ) -> RB + DynSend ,
360365 {
361- if mode:: active ( ) {
366+ if mode:: is_dyn_thread_safe ( ) {
362367 let oper_a = FromDyn :: from( oper_a) ;
363368 let oper_b = FromDyn :: from( oper_b) ;
364369 let ( a, b) = rayon:: join( move || FromDyn :: from( oper_a. into_inner( ) ( ) ) , move || FromDyn :: from( oper_b. into_inner( ) ( ) ) ) ;
@@ -368,7 +373,7 @@ cfg_if! {
368373 }
369374 }
370375
371- // This function only works when `mode::active ()`.
376+ // This function only works when `mode::is_dyn_thread_safe ()`.
372377 pub fn scope<' scope, OP , R >( op: OP ) -> R
373378 where
374379 OP : FnOnce ( & rayon:: Scope <' scope>) -> R + DynSend ,
@@ -393,7 +398,7 @@ cfg_if! {
393398 } ) ;
394399 } ;
395400 ( $fblock: block, $( $blocks: block) , * ) => {
396- if rustc_data_structures:: sync:: active ( ) {
401+ if rustc_data_structures:: sync:: is_dyn_thread_safe ( ) {
397402 // Reverse the order of the later blocks since Rayon executes them in reverse order
398403 // when using a single thread. This ensures the execution order matches that
399404 // of a single threaded rustc
@@ -431,7 +436,7 @@ cfg_if! {
431436 t: T ,
432437 for_each: impl Fn ( I ) + DynSync + DynSend
433438 ) {
434- if mode:: active ( ) {
439+ if mode:: is_dyn_thread_safe ( ) {
435440 let for_each = FromDyn :: from( for_each) ;
436441 let panic: Lock <Option <_>> = Lock :: new( None ) ;
437442 t. into_par_iter( ) . for_each( |i| if let Err ( p) = catch_unwind( AssertUnwindSafe ( || for_each( i) ) ) {
@@ -470,7 +475,7 @@ cfg_if! {
470475 t: T ,
471476 map: impl Fn ( I ) -> R + DynSync + DynSend
472477 ) -> C {
473- if mode:: active ( ) {
478+ if mode:: is_dyn_thread_safe ( ) {
474479 let panic: Lock <Option <_>> = Lock :: new( None ) ;
475480 let map = FromDyn :: from( map) ;
476481 // We catch panics here ensuring that all the loop iterations execute.
0 commit comments