@@ -12,7 +12,6 @@ use std::{
12
12
io:: { BufRead , BufReader } ,
13
13
path:: { Path , PathBuf } ,
14
14
process:: { Command , Stdio } ,
15
- thread:: JoinHandle ,
16
15
time:: Instant ,
17
16
} ;
18
17
@@ -37,8 +36,9 @@ pub struct CheckOptions {
37
36
#[ derive( Debug ) ]
38
37
pub struct CheckWatcher {
39
38
pub task_recv : Receiver < CheckTask > ,
39
+ // XXX: drop order is significant
40
40
cmd_send : Option < Sender < CheckCommand > > ,
41
- handle : Option < JoinHandle < ( ) > > ,
41
+ handle : Option < jod_thread :: JoinHandle < ( ) > > ,
42
42
}
43
43
44
44
impl CheckWatcher {
@@ -47,7 +47,7 @@ impl CheckWatcher {
47
47
48
48
let ( task_send, task_recv) = unbounded :: < CheckTask > ( ) ;
49
49
let ( cmd_send, cmd_recv) = unbounded :: < CheckCommand > ( ) ;
50
- let handle = std :: thread :: spawn ( move || {
50
+ let handle = jod_thread :: spawn ( move || {
51
51
let mut check = CheckWatcherThread :: new ( options, workspace_root) ;
52
52
check. run ( & task_send, & cmd_recv) ;
53
53
} ) ;
@@ -67,22 +67,6 @@ impl CheckWatcher {
67
67
}
68
68
}
69
69
70
- impl std:: ops:: Drop for CheckWatcher {
71
- fn drop ( & mut self ) {
72
- if let Some ( handle) = self . handle . take ( ) {
73
- // Take the sender out of the option
74
- let cmd_send = self . cmd_send . take ( ) ;
75
-
76
- // Dropping the sender finishes the thread loop
77
- drop ( cmd_send) ;
78
-
79
- // Join the thread, it should finish shortly. We don't really care
80
- // whether it panicked, so it is safe to ignore the result
81
- let _ = handle. join ( ) ;
82
- }
83
- }
84
- }
85
-
86
70
#[ derive( Debug ) ]
87
71
pub enum CheckTask {
88
72
/// Request a clearing of all cached diagnostics from the check watcher
@@ -237,8 +221,9 @@ pub struct DiagnosticWithFixes {
237
221
/// The correct way to dispose of the thread is to drop it, on which the
238
222
/// sub-process will be killed, and the thread will be joined.
239
223
struct WatchThread {
240
- handle : Option < JoinHandle < ( ) > > ,
224
+ // XXX: drop order is significant
241
225
message_recv : Receiver < CheckEvent > ,
226
+ _handle : Option < jod_thread:: JoinHandle < ( ) > > ,
242
227
}
243
228
244
229
enum CheckEvent {
@@ -333,7 +318,7 @@ pub fn run_cargo(
333
318
334
319
impl WatchThread {
335
320
fn dummy ( ) -> WatchThread {
336
- WatchThread { handle : None , message_recv : never ( ) }
321
+ WatchThread { message_recv : never ( ) , _handle : None }
337
322
}
338
323
339
324
fn new ( options : & CheckOptions , workspace_root : & Path ) -> WatchThread {
@@ -352,7 +337,7 @@ impl WatchThread {
352
337
let ( message_send, message_recv) = unbounded ( ) ;
353
338
let workspace_root = workspace_root. to_owned ( ) ;
354
339
let handle = if options. enable {
355
- Some ( std :: thread :: spawn ( move || {
340
+ Some ( jod_thread :: spawn ( move || {
356
341
// If we trigger an error here, we will do so in the loop instead,
357
342
// which will break out of the loop, and continue the shutdown
358
343
let _ = message_send. send ( CheckEvent :: Begin ) ;
@@ -383,23 +368,6 @@ impl WatchThread {
383
368
} else {
384
369
None
385
370
} ;
386
- WatchThread { handle, message_recv }
387
- }
388
- }
389
-
390
- impl std:: ops:: Drop for WatchThread {
391
- fn drop ( & mut self ) {
392
- if let Some ( handle) = self . handle . take ( ) {
393
- // Replace our reciever with dummy one, so we can drop and close the
394
- // one actually communicating with the thread
395
- let recv = std:: mem:: replace ( & mut self . message_recv , never ( ) ) ;
396
-
397
- // Dropping the original reciever initiates thread sub-process shutdown
398
- drop ( recv) ;
399
-
400
- // Join the thread, it should finish shortly. We don't really care
401
- // whether it panicked, so it is safe to ignore the result
402
- let _ = handle. join ( ) ;
403
- }
371
+ WatchThread { message_recv, _handle : handle }
404
372
}
405
373
}
0 commit comments