• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #![cfg_attr(not(feature = "rt"), allow(dead_code))]
2 
3 //! Process driver.
4 
5 use crate::park::Park;
6 use crate::process::unix::GlobalOrphanQueue;
7 use crate::signal::unix::driver::{Driver as SignalDriver, Handle as SignalHandle};
8 
9 use std::io;
10 use std::time::Duration;
11 
12 /// Responsible for cleaning up orphaned child processes on Unix platforms.
13 #[derive(Debug)]
14 pub(crate) struct Driver {
15     park: SignalDriver,
16     signal_handle: SignalHandle,
17 }
18 
19 // ===== impl Driver =====
20 
21 impl Driver {
22     /// Creates a new signal `Driver` instance that delegates wakeups to `park`.
new(park: SignalDriver) -> Self23     pub(crate) fn new(park: SignalDriver) -> Self {
24         let signal_handle = park.handle();
25 
26         Self {
27             park,
28             signal_handle,
29         }
30     }
31 }
32 
33 // ===== impl Park for Driver =====
34 
35 impl Park for Driver {
36     type Unpark = <SignalDriver as Park>::Unpark;
37     type Error = io::Error;
38 
unpark(&self) -> Self::Unpark39     fn unpark(&self) -> Self::Unpark {
40         self.park.unpark()
41     }
42 
park(&mut self) -> Result<(), Self::Error>43     fn park(&mut self) -> Result<(), Self::Error> {
44         self.park.park()?;
45         GlobalOrphanQueue::reap_orphans(&self.signal_handle);
46         Ok(())
47     }
48 
park_timeout(&mut self, duration: Duration) -> Result<(), Self::Error>49     fn park_timeout(&mut self, duration: Duration) -> Result<(), Self::Error> {
50         self.park.park_timeout(duration)?;
51         GlobalOrphanQueue::reap_orphans(&self.signal_handle);
52         Ok(())
53     }
54 
shutdown(&mut self)55     fn shutdown(&mut self) {
56         self.park.shutdown()
57     }
58 }
59