1 | #![cfg_attr (not(feature = "rt" ), allow(dead_code))] |
2 | |
3 | //! Process driver. |
4 | |
5 | use crate::process::unix::GlobalOrphanQueue; |
6 | use crate::runtime::driver; |
7 | use crate::runtime::signal::{Driver as SignalDriver, Handle as SignalHandle}; |
8 | |
9 | use std::time::Duration; |
10 | |
11 | /// Responsible for cleaning up orphaned child processes on Unix platforms. |
12 | #[derive(Debug)] |
13 | pub(crate) struct Driver { |
14 | park: SignalDriver, |
15 | signal_handle: SignalHandle, |
16 | } |
17 | |
18 | // ===== impl Driver ===== |
19 | |
20 | impl Driver { |
21 | /// Creates a new signal `Driver` instance that delegates wakeups to `park`. |
22 | pub(crate) fn new(park: SignalDriver) -> Self { |
23 | let signal_handle = park.handle(); |
24 | |
25 | Self { |
26 | park, |
27 | signal_handle, |
28 | } |
29 | } |
30 | |
31 | pub(crate) fn park(&mut self, handle: &driver::Handle) { |
32 | self.park.park(handle); |
33 | GlobalOrphanQueue::reap_orphans(&self.signal_handle); |
34 | } |
35 | |
36 | pub(crate) fn park_timeout(&mut self, handle: &driver::Handle, duration: Duration) { |
37 | self.park.park_timeout(handle, duration); |
38 | GlobalOrphanQueue::reap_orphans(&self.signal_handle); |
39 | } |
40 | |
41 | pub(crate) fn shutdown(&mut self, handle: &driver::Handle) { |
42 | self.park.shutdown(handle); |
43 | } |
44 | } |
45 | |