Skip to main content

Guard

Struct Guard 

Source
pub struct Guard { /* private fields */ }
Expand description

RAII timing guard. Records elapsed time on drop.

16 bytes: fits in two registers on both x86_64 (rax+rdx) and aarch64 (x0+x1), eliminating all memory stores from the measurement window.

Uses a raw hardware counter (rdtsc / cntvct_el0) instead of Instant::now() to minimize clock-read cost. The tsc-to-nanosecond conversion happens in drop_cold, outside the measurement window.

Implementations§

Source§

impl Guard

Source

pub fn check(&self)

Check for thread migration after an .await point.

If the Guard has migrated to a different thread, pushes a phantom StackEntry onto the new thread’s stack so that children can update it via the normal parent fast path. Also registers the Guard as migrated so the original thread can clean up the orphaned entry.

No-op if still on the same thread. Idempotent: safe to call multiple times (skips if phantom already exists on current stack).

Trait Implementations§

Source§

impl Drop for Guard

Source§

fn drop(&mut self)

Inlined so the counter read (rdtsc/cntvct_el0) happens at the drop site as a single inline instruction. compiler_fence prevents the compiler from hoisting Guard field loads before the counter read.

Auto Trait Implementations§

§

impl Freeze for Guard

§

impl RefUnwindSafe for Guard

§

impl Send for Guard

§

impl Sync for Guard

§

impl Unpin for Guard

§

impl UnsafeUnpin for Guard

§

impl UnwindSafe for Guard

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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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