@@ -31,7 +31,7 @@ use std::{
31
31
} ,
32
32
os:: fd:: AsRawFd ,
33
33
process, ptr,
34
- sync:: { Arc , Mutex , OnceLock } ,
34
+ sync:: { Arc , LazyLock , Mutex } ,
35
35
thread,
36
36
time:: { Duration , Instant } ,
37
37
} ;
@@ -53,12 +53,9 @@ pub struct State {
53
53
pub talkd_addr : SocketAddr ,
54
54
}
55
55
56
- fn get_delete_invitations ( ) -> & ' static Arc < Mutex < Option < State > > > {
57
- /// A static variable to hold the state of delete invitations on SIGINT signal.
58
- static DELETE_INVITATIONS : OnceLock < Arc < Mutex < Option < State > > > > = OnceLock :: new ( ) ;
59
-
60
- DELETE_INVITATIONS . get_or_init ( || Arc :: new ( Mutex :: new ( None ) ) )
61
- }
56
+ /// A static variable to hold the state of delete invitations on SIGINT signal.
57
+ static DELETE_INVITATIONS : LazyLock < Arc < Mutex < Option < State > > > > =
58
+ LazyLock :: new ( || Arc :: new ( Mutex :: new ( None ) ) ) ;
62
59
63
60
/// The size of the buffer for control message fields like l_name, r_name, and r_tty in CtlMsg.
64
61
const BUFFER_SIZE : usize = 12 ;
@@ -962,7 +959,7 @@ fn handle_new_invitation(
962
959
963
960
let clone_socket = Arc :: clone ( & socket) ;
964
961
965
- * get_delete_invitations ( ) . lock ( ) . unwrap ( ) = Some ( State {
962
+ * DELETE_INVITATIONS . lock ( ) . unwrap ( ) = Some ( State {
966
963
msg_bytes1,
967
964
msg_bytes2,
968
965
socket : clone_socket,
@@ -1630,7 +1627,7 @@ pub fn handle_signals(signal_code: libc::c_int) {
1630
1627
eprintln ! ( "Connection closed, exiting..." ) ;
1631
1628
1632
1629
// Lock the DELETE_INVITATIONS mutex and check for an existing invitation
1633
- if let Some ( state) = get_delete_invitations ( ) . lock ( ) . unwrap ( ) . as_ref ( ) {
1630
+ if let Some ( state) = DELETE_INVITATIONS . lock ( ) . unwrap ( ) . as_ref ( ) {
1634
1631
// Handle the deletion of invitations
1635
1632
handle_delete_invitations ( & state. socket , & state. msg_bytes1 , & state. talkd_addr ) ;
1636
1633
handle_delete_invitations ( & state. socket , & state. msg_bytes2 , & state. talkd_addr ) ;
0 commit comments