@@ -31,7 +31,7 @@ use std::{
3131 } ,
3232 os:: fd:: AsRawFd ,
3333 process, ptr,
34- sync:: { Arc , Mutex , OnceLock } ,
34+ sync:: { Arc , LazyLock , Mutex } ,
3535 thread,
3636 time:: { Duration , Instant } ,
3737} ;
@@ -53,12 +53,9 @@ pub struct State {
5353 pub talkd_addr : SocketAddr ,
5454}
5555
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 ) ) ) ;
6259
6360/// The size of the buffer for control message fields like l_name, r_name, and r_tty in CtlMsg.
6461const BUFFER_SIZE : usize = 12 ;
@@ -962,7 +959,7 @@ fn handle_new_invitation(
962959
963960 let clone_socket = Arc :: clone ( & socket) ;
964961
965- * get_delete_invitations ( ) . lock ( ) . unwrap ( ) = Some ( State {
962+ * DELETE_INVITATIONS . lock ( ) . unwrap ( ) = Some ( State {
966963 msg_bytes1,
967964 msg_bytes2,
968965 socket : clone_socket,
@@ -1630,7 +1627,7 @@ pub fn handle_signals(signal_code: libc::c_int) {
16301627 eprintln ! ( "Connection closed, exiting..." ) ;
16311628
16321629 // 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 ( ) {
16341631 // Handle the deletion of invitations
16351632 handle_delete_invitations ( & state. socket , & state. msg_bytes1 , & state. talkd_addr ) ;
16361633 handle_delete_invitations ( & state. socket , & state. msg_bytes2 , & state. talkd_addr ) ;
0 commit comments