@@ -13,7 +13,6 @@ mod stats;
1313
1414use std:: net:: SocketAddr ;
1515use std:: sync:: Arc ;
16- use std:: sync:: atomic:: { AtomicBool , Ordering } ;
1716
1817use crate :: config:: { parse_args, parse_config} ;
1918use crate :: diag:: run_diag_read_thread;
@@ -43,8 +42,8 @@ use rayhunter::diag_device::DiagDevice;
4342use stats:: get_log;
4443use tokio:: net:: TcpListener ;
4544use tokio:: select;
45+ use tokio:: sync:: RwLock ;
4646use tokio:: sync:: mpsc:: { self , Sender } ;
47- use tokio:: sync:: { RwLock , oneshot} ;
4847use tokio:: task:: JoinHandle ;
4948use tokio_util:: sync:: CancellationToken ;
5049use tokio_util:: task:: TaskTracker ;
@@ -126,12 +125,9 @@ async fn init_qmdl_store(config: &config::Config) -> Result<RecordingStore, Rayh
126125// Start a thread that'll track when user hits ctrl+c. When that happens,
127126// trigger various cleanup tasks, including sending signals to other threads to
128127// shutdown
129- #[ allow( clippy:: too_many_arguments) ]
130128fn run_shutdown_thread (
131129 task_tracker : & TaskTracker ,
132130 diag_device_sender : Sender < DiagDeviceCtrlMessage > ,
133- daemon_restart_rx : oneshot:: Receiver < ( ) > ,
134- should_restart_flag : Arc < AtomicBool > ,
135131 shutdown_token : CancellationToken ,
136132 qmdl_store_lock : Arc < RwLock < RecordingStore > > ,
137133 analysis_tx : Sender < AnalysisCtrlMessage > ,
@@ -144,17 +140,9 @@ fn run_shutdown_thread(
144140 if let Err ( err) = res {
145141 error!( "Unable to listen for shutdown signal: {err}" ) ;
146142 }
147-
148- should_restart_flag. store( false , Ordering :: Relaxed ) ;
149- }
150- res = daemon_restart_rx => {
151- if let Err ( err) = res {
152- error!( "Unable to listen for shutdown signal: {err}" ) ;
153- }
154-
155- should_restart_flag. store( true , Ordering :: Relaxed ) ;
156143 }
157- } ;
144+ _ = shutdown_token. cancelled( ) => { }
145+ }
158146
159147 let mut qmdl_store = qmdl_store_lock. write ( ) . await ;
160148 if qmdl_store. current_entry . is_some ( ) {
@@ -209,7 +197,8 @@ async fn run_with_config(
209197 let ( diag_tx, diag_rx) = mpsc:: channel :: < DiagDeviceCtrlMessage > ( 1 ) ;
210198 let ( ui_update_tx, ui_update_rx) = mpsc:: channel :: < display:: DisplayState > ( 1 ) ;
211199 let ( analysis_tx, analysis_rx) = mpsc:: channel :: < AnalysisCtrlMessage > ( 5 ) ;
212- let shutdown_token = CancellationToken :: new ( ) ;
200+ let restart_token = CancellationToken :: new ( ) ;
201+ let shutdown_token = restart_token. child_token ( ) ;
213202
214203 let notification_service = NotificationService :: new ( config. ntfy_url . clone ( ) ) ;
215204
@@ -255,7 +244,6 @@ async fn run_with_config(
255244 ) ;
256245 }
257246
258- let ( daemon_restart_tx, daemon_restart_rx) = oneshot:: channel :: < ( ) > ( ) ;
259247 let analysis_status_lock = Arc :: new ( RwLock :: new ( analysis_status) ) ;
260248 run_analysis_thread (
261249 & task_tracker,
@@ -264,13 +252,10 @@ async fn run_with_config(
264252 analysis_status_lock. clone ( ) ,
265253 config. analyzers . clone ( ) ,
266254 ) ;
267- let should_restart_flag = Arc :: new ( AtomicBool :: new ( false ) ) ;
268255
269256 run_shutdown_thread (
270257 & task_tracker,
271258 diag_tx. clone ( ) ,
272- daemon_restart_rx,
273- should_restart_flag. clone ( ) ,
274259 shutdown_token. clone ( ) ,
275260 qmdl_store_lock. clone ( ) ,
276261 analysis_tx. clone ( ) ,
@@ -283,7 +268,7 @@ async fn run_with_config(
283268 diag_device_ctrl_sender : diag_tx,
284269 analysis_status_lock,
285270 analysis_sender : analysis_tx,
286- daemon_restart_tx : Arc :: new ( RwLock :: new ( Some ( daemon_restart_tx ) ) ) ,
271+ daemon_restart_token : restart_token . clone ( ) ,
287272 ui_update_sender : Some ( ui_update_tx) ,
288273 } ) ;
289274 run_server ( & task_tracker, state, shutdown_token. clone ( ) ) . await ;
@@ -292,7 +277,7 @@ async fn run_with_config(
292277 task_tracker. wait ( ) . await ;
293278
294279 info ! ( "see you space cowboy..." ) ;
295- Ok ( should_restart_flag . load ( Ordering :: Relaxed ) )
280+ Ok ( restart_token . is_cancelled ( ) )
296281}
297282
298283#[ cfg( test) ]
0 commit comments