use std::{convert, process};
#[derive(Debug)]
pub struct Guard {
last_pid: u32,
}
impl Default for Guard {
fn default() -> Self {
let last_pid = process::id();
Self { last_pid }
}
}
impl Guard {
pub fn try_new() -> Result<Self, convert::Infallible> {
Ok(Default::default())
}
#[inline(always)]
pub fn detected_fork(&mut self) -> bool {
let current_pid = process::id();
if self.last_pid == current_pid {
false
} else {
self.set_pid(current_pid);
true
}
}
#[cold]
fn set_pid(&mut self, value: u32) {
self.last_pid = value;
}
}