@@ -9,14 +9,18 @@ mod needs_feature {
99 static V1 : AtomicUsize = AtomicUsize :: new ( 0 ) ;
1010 static V2 : AtomicBool = AtomicBool :: new ( false ) ;
1111
12- let reg1 = gix:: interrupt:: init_handler ( 3 , || {
13- V1 . fetch_add ( 1 , Ordering :: SeqCst ) ;
14- } )
12+ // SAFETY: The closure doesn't use mutexes or memory allocation, so it should be safe to call from a signal handler.
13+ let reg1 = unsafe {
14+ gix:: interrupt:: init_handler ( 3 , || {
15+ V1 . fetch_add ( 1 , Ordering :: SeqCst ) ;
16+ } )
17+ }
1518 . expect ( "succeeds" ) ;
1619 assert ! ( !gix:: interrupt:: is_triggered( ) ) ;
1720 assert_eq ! ( V1 . load( Ordering :: Relaxed ) , 0 ) ;
18- let reg2 =
19- gix:: interrupt:: init_handler ( 2 , || V2 . store ( true , Ordering :: SeqCst ) ) . expect ( "multi-initialization is OK" ) ;
21+ // SAFETY: The closure doesn't use mutexes or memory allocation, so it should be safe to call from a signal handler.
22+ let reg2 = unsafe { gix:: interrupt:: init_handler ( 2 , || V2 . store ( true , Ordering :: SeqCst ) ) }
23+ . expect ( "multi-initialization is OK" ) ;
2024 assert ! ( !V2 . load( Ordering :: Relaxed ) ) ;
2125
2226 signal_hook:: low_level:: raise ( SIGTERM ) . expect ( "signal can be raised" ) ;
@@ -36,13 +40,17 @@ mod needs_feature {
3640 "the deregistration succeeded and this is an optional side-effect"
3741 ) ;
3842
39- let reg1 = gix:: interrupt:: init_handler ( 3 , || {
40- V1 . fetch_add ( 1 , Ordering :: SeqCst ) ;
41- } )
43+ // SAFETY: The closure doesn't use mutexes or memory allocation, so it should be safe to call from a signal handler.
44+ let reg1 = unsafe {
45+ gix:: interrupt:: init_handler ( 3 , || {
46+ V1 . fetch_add ( 1 , Ordering :: SeqCst ) ;
47+ } )
48+ }
4249 . expect ( "succeeds" ) ;
4350 assert_eq ! ( V1 . load( Ordering :: Relaxed ) , 2 , "nothing changed yet" ) ;
44- let reg2 =
45- gix:: interrupt:: init_handler ( 2 , || V2 . store ( true , Ordering :: SeqCst ) ) . expect ( "multi-initialization is OK" ) ;
51+ // SAFETY: The closure doesn't use mutexes or memory allocation, so it should be safe to call from a signal handler.
52+ let reg2 = unsafe { gix:: interrupt:: init_handler ( 2 , || V2 . store ( true , Ordering :: SeqCst ) ) }
53+ . expect ( "multi-initialization is OK" ) ;
4654 assert ! ( !V2 . load( Ordering :: Relaxed ) ) ;
4755
4856 signal_hook:: low_level:: raise ( SIGTERM ) . expect ( "signal can be raised" ) ;
0 commit comments