pub struct SystemPressure { /* private fields */ }Expand description
Atomic system pressure state shared via Arc<SystemPressure>.
Headroom is stored as a u32 bit pattern of an f32 and accessed with
relaxed atomics — good enough for advisory pressure signals where
occasional stale reads are acceptable.
Implementations§
Source§impl SystemPressure
impl SystemPressure
Sourcepub fn with_headroom(headroom: f32) -> Self
pub fn with_headroom(headroom: f32) -> Self
Create with an explicit initial headroom value.
Headroom is clamped to [0.0, 1.0]. NaN inputs are treated as
0.0 (fully degraded — fail-safe), see [sanitise_headroom].
Sourcepub fn headroom(&self) -> f32
pub fn headroom(&self) -> f32
Read the current headroom (0.0–1.0).
Uses Relaxed ordering — reads may be slightly stale but are
always valid f32 values in [0.0, 1.0].
Sourcepub fn set_headroom(&self, headroom: f32)
pub fn set_headroom(&self, headroom: f32)
Update the headroom value.
Headroom is clamped to [0.0, 1.0]. NaN inputs are treated as
0.0 (fully degraded — fail-safe), see [sanitise_headroom].
Sourcepub fn should_degrade(&self, threshold: f32) -> bool
pub fn should_degrade(&self, threshold: f32) -> bool
True if headroom is below the given threshold.
Sourcepub fn degradation_level(&self) -> u8
pub fn degradation_level(&self) -> u8
Degradation level (0–4) based on headroom thresholds.
The cut points intentionally mirror
runtime::resource_monitor::DegradationLevel::from_headroom so a
SystemPressure cloned out of the resource monitor reports the same
public severity band:
- Level 0: headroom > 0.875 (Normal)
- Level 1: headroom > 0.625 (Light)
- Level 2: headroom > 0.375 (Moderate)
- Level 3: headroom > 0.125 (Heavy)
- Level 4: headroom <= 0.125 (Emergency)
Sourcepub fn level_label(&self) -> &'static str
pub fn level_label(&self) -> &'static str
Human-readable label for the current degradation level.