ifc_lite_geometry_runtime/
runtime_owner.rs

1// SPDX-License-Identifier: MPL-2.0
2//! Small live-process capability; carries no source, model or numerical data.
3use crate::process_control::ProcessControl;
4
5/// Shared authority over the exact worker process that produced a receipt.
6#[derive(Clone)]
7pub struct RuntimeOwner {
8    control: ProcessControl,
9    incarnation: u64,
10}
11
12impl RuntimeOwner {
13    /// Identity of the captured process authority, including after retirement.
14    /// Never compare numeric PIDs or caller-supplied incarnation values.
15    #[cfg(feature = "retained-runtime")]
16    pub fn same_domain(&self, other: &Self) -> bool { self.control.same_domain(&other.control) }
17    pub(crate) fn new(control: ProcessControl, incarnation: u64) -> Self {
18        Self {
19            control,
20            incarnation,
21        }
22    }
23
24    /// Retire and reap this captured process, invalidating every shared handle.
25    /// Safe after a replacement starts: authority never resolves a numeric PID.
26    pub fn retire(&self) {
27        if let Err(error) = self.control.terminate() {
28            eprintln!("geometry runtime owner retirement/reap failed: {error}");
29        }
30    }
31
32    /// The worker incarnation while its captured process is live. Observes the
33    /// actual child exit and shared retirement; never trusts a PID.
34    pub fn incarnation(&self) -> Option<u64> {
35        self.control.is_live().then_some(self.incarnation)
36    }
37}
38
39impl std::fmt::Debug for RuntimeOwner {
40    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
41        f.debug_struct("RuntimeOwner")
42            .field("incarnation", &self.incarnation())
43            .finish()
44    }
45}