@@ -13,7 +13,6 @@ mod stats;
13
13
14
14
use std:: net:: SocketAddr ;
15
15
use std:: sync:: Arc ;
16
- use std:: sync:: atomic:: { AtomicBool , Ordering } ;
17
16
18
17
use crate :: config:: { parse_args, parse_config} ;
19
18
use crate :: diag:: run_diag_read_thread;
@@ -43,8 +42,8 @@ use rayhunter::diag_device::DiagDevice;
43
42
use stats:: get_log;
44
43
use tokio:: net:: TcpListener ;
45
44
use tokio:: select;
45
+ use tokio:: sync:: RwLock ;
46
46
use tokio:: sync:: mpsc:: { self , Sender } ;
47
- use tokio:: sync:: { RwLock , oneshot} ;
48
47
use tokio:: task:: JoinHandle ;
49
48
use tokio_util:: sync:: CancellationToken ;
50
49
use tokio_util:: task:: TaskTracker ;
@@ -126,12 +125,9 @@ async fn init_qmdl_store(config: &config::Config) -> Result<RecordingStore, Rayh
126
125
// Start a thread that'll track when user hits ctrl+c. When that happens,
127
126
// trigger various cleanup tasks, including sending signals to other threads to
128
127
// shutdown
129
- #[ allow( clippy:: too_many_arguments) ]
130
128
fn run_shutdown_thread (
131
129
task_tracker : & TaskTracker ,
132
130
diag_device_sender : Sender < DiagDeviceCtrlMessage > ,
133
- daemon_restart_rx : oneshot:: Receiver < ( ) > ,
134
- should_restart_flag : Arc < AtomicBool > ,
135
131
shutdown_token : CancellationToken ,
136
132
qmdl_store_lock : Arc < RwLock < RecordingStore > > ,
137
133
analysis_tx : Sender < AnalysisCtrlMessage > ,
@@ -144,17 +140,9 @@ fn run_shutdown_thread(
144
140
if let Err ( err) = res {
145
141
error!( "Unable to listen for shutdown signal: {err}" ) ;
146
142
}
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 ) ;
156
143
}
157
- } ;
144
+ _ = shutdown_token. cancelled( ) => { }
145
+ }
158
146
159
147
let mut qmdl_store = qmdl_store_lock. write ( ) . await ;
160
148
if qmdl_store. current_entry . is_some ( ) {
@@ -209,7 +197,8 @@ async fn run_with_config(
209
197
let ( diag_tx, diag_rx) = mpsc:: channel :: < DiagDeviceCtrlMessage > ( 1 ) ;
210
198
let ( ui_update_tx, ui_update_rx) = mpsc:: channel :: < display:: DisplayState > ( 1 ) ;
211
199
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 ( ) ;
213
202
214
203
let notification_service = NotificationService :: new ( config. ntfy_url . clone ( ) ) ;
215
204
@@ -255,7 +244,6 @@ async fn run_with_config(
255
244
) ;
256
245
}
257
246
258
- let ( daemon_restart_tx, daemon_restart_rx) = oneshot:: channel :: < ( ) > ( ) ;
259
247
let analysis_status_lock = Arc :: new ( RwLock :: new ( analysis_status) ) ;
260
248
run_analysis_thread (
261
249
& task_tracker,
@@ -264,13 +252,10 @@ async fn run_with_config(
264
252
analysis_status_lock. clone ( ) ,
265
253
config. analyzers . clone ( ) ,
266
254
) ;
267
- let should_restart_flag = Arc :: new ( AtomicBool :: new ( false ) ) ;
268
255
269
256
run_shutdown_thread (
270
257
& task_tracker,
271
258
diag_tx. clone ( ) ,
272
- daemon_restart_rx,
273
- should_restart_flag. clone ( ) ,
274
259
shutdown_token. clone ( ) ,
275
260
qmdl_store_lock. clone ( ) ,
276
261
analysis_tx. clone ( ) ,
@@ -283,7 +268,7 @@ async fn run_with_config(
283
268
diag_device_ctrl_sender : diag_tx,
284
269
analysis_status_lock,
285
270
analysis_sender : analysis_tx,
286
- daemon_restart_tx : Arc :: new ( RwLock :: new ( Some ( daemon_restart_tx ) ) ) ,
271
+ daemon_restart_token : restart_token . clone ( ) ,
287
272
ui_update_sender : Some ( ui_update_tx) ,
288
273
} ) ;
289
274
run_server ( & task_tracker, state, shutdown_token. clone ( ) ) . await ;
@@ -292,7 +277,7 @@ async fn run_with_config(
292
277
task_tracker. wait ( ) . await ;
293
278
294
279
info ! ( "see you space cowboy..." ) ;
295
- Ok ( should_restart_flag . load ( Ordering :: Relaxed ) )
280
+ Ok ( restart_token . is_cancelled ( ) )
296
281
}
297
282
298
283
#[ cfg( test) ]
0 commit comments