Skip to main content

SystemPressure

Struct SystemPressure 

Source
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

Source

pub fn new() -> Self

Create a new pressure state at full headroom (1.0).

Source

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].

Source

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].

Source

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].

Source

pub fn should_degrade(&self, threshold: f32) -> bool

True if headroom is below the given threshold.

Source

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)
Source

pub fn level_label(&self) -> &'static str

Human-readable label for the current degradation level.

Trait Implementations§

Source§

impl Debug for SystemPressure

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SystemPressure

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V