1- #![ cfg_attr( target_os = "wasi" , allow( dead_code) ) ]
21use crate :: { PyObjectRef , PyResult , VirtualMachine } ;
32use alloc:: fmt;
43use core:: cell:: { Cell , RefCell } ;
5- #[ cfg( windows) ]
6- use core:: sync:: atomic:: AtomicIsize ;
74use core:: sync:: atomic:: { AtomicBool , Ordering } ;
85use std:: sync:: mpsc;
96
10- pub ( crate ) const NSIG : usize = 64 ;
7+ #[ cfg( windows) ]
8+ use core:: sync:: atomic:: AtomicIsize ;
119
12- pub ( crate ) fn new_signal_handlers ( ) -> Box < RefCell < [ Option < PyObjectRef > ; NSIG ] > > {
13- Box :: new ( const { RefCell :: new ( [ const { None } ; NSIG ] ) } )
14- }
1510static ANY_TRIGGERED : AtomicBool = AtomicBool :: new ( false ) ;
16- // hack to get around const array repeat expressions, rust issue #79270
17- #[ allow(
11+
12+ pub ( crate ) const NSIG : usize = 64 ;
13+
14+ #[ expect(
1815 clippy:: declare_interior_mutable_const,
1916 reason = "workaround for const array repeat limitation (rust issue #79270)"
2017) ]
2118const ATOMIC_FALSE : AtomicBool = AtomicBool :: new ( false ) ;
19+
2220pub ( crate ) static TRIGGERS : [ AtomicBool ; NSIG ] = [ ATOMIC_FALSE ; NSIG ] ;
2321
2422#[ cfg( windows) ]
2523static SIGINT_EVENT : AtomicIsize = AtomicIsize :: new ( 0 ) ;
2624
25+ pub ( crate ) fn new_signal_handlers ( ) -> Box < RefCell < [ Option < PyObjectRef > ; NSIG ] > > {
26+ Box :: new ( const { RefCell :: new ( [ const { None } ; NSIG ] ) } )
27+ }
28+
2729thread_local ! {
2830 /// Prevent recursive signal handler invocation. When a Python signal
2931 /// handler is running, new signals are deferred until it completes.
@@ -50,6 +52,7 @@ pub fn check_signals(vm: &VirtualMachine) -> PyResult<()> {
5052 if !ANY_TRIGGERED . load ( Ordering :: Relaxed ) {
5153 return Ok ( ( ) ) ;
5254 }
55+
5356 // Atomic RMW only when a signal is actually pending.
5457 if !ANY_TRIGGERED . swap ( false , Ordering :: Acquire ) {
5558 return Ok ( ( ) ) ;
@@ -99,8 +102,7 @@ pub(crate) fn is_triggered() -> bool {
99102
100103/// Reset all signal trigger state after fork in child process.
101104/// Stale triggers from the parent must not fire in the child.
102- #[ cfg( unix) ]
103- #[ cfg( feature = "host_env" ) ]
105+ #[ cfg( all( unix, feature = "host_env" ) ) ]
104106pub ( crate ) fn clear_after_fork ( ) {
105107 ANY_TRIGGERED . store ( false , Ordering :: Release ) ;
106108 for trigger in & TRIGGERS {
0 commit comments