Skip to main content

endpoint_sec/event/
event_signal.rs

1//! [`EventSignal`]
2
3use endpoint_sec_sys::es_event_signal_t;
4
5use crate::Process;
6
7/// Send a signal to a process event.
8#[doc(alias = "es_event_signal_t")]
9pub struct EventSignal<'a> {
10    /// The raw reference.
11    pub(crate) raw: &'a es_event_signal_t,
12
13    /// The version of the message.
14    pub(crate) version: u32,
15}
16
17impl<'a> EventSignal<'a> {
18    /// The signal number to be delivered.
19    #[inline(always)]
20    pub fn sig(&self) -> i32 {
21        self.raw.sig
22    }
23
24    /// The process that will receive the signal.
25    #[inline(always)]
26    pub fn target(&self) -> Process<'a> {
27        // Safety: 'a tied to self, object obtained through ES
28        Process::new(unsafe { self.raw.target() }, self.version)
29    }
30}
31
32// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
33unsafe impl Send for EventSignal<'_> {}
34// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
35unsafe impl Sync for EventSignal<'_> {}
36
37impl_debug_eq_hash_with_functions!(EventSignal<'a> with version; sig, target);