Skip to main content

ScopeCell

Struct ScopeCell 

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

A scope whose scheduler binding owns one shared lease while active.

Scheduler hooks acquire the lease before publishing the pinned pointer and release it after clearing that pointer. Scope-local hot reads therefore need no per-access lock. Every contended operation returns ScopeCellBusy without waiting in a non-preemptible context.

Implementations§

Source§

impl ScopeCell

Source

pub fn new() -> Self

Creates a managed scope with no active scheduler binding.

Source

pub fn from_scope(scope: Scope) -> Self

Wraps an existing scope with a managed scheduler binding.

Source

pub fn try_read(&self) -> Result<ScopeCellReadGuard<'_>, ScopeCellBusy>

Attempts to acquire an ordinary shared scope reference while preventing migration. It returns immediately when an exclusive lease is active.

Source

pub fn try_write(&self) -> Result<ScopeCellWriteGuard<'_>, ScopeCellBusy>

Attempts to acquire an ordinary exclusive scope reference while preventing migration. It returns immediately while any lease is live.

Source

pub unsafe fn try_activate_pinned( &self, pin: &CpuPin<'_>, ) -> Result<(), ScopeActivationError>

Attempts to install this scope for the pinned CPU and retain its sole scheduler lease.

This operation does not enter a new IRQ or preemption context, so it is suitable for a scheduler switch-in hook that already owns its CPU-local baton.

§Safety

Only one CPU may activate a cell at a time. On success, the caller must keep this ScopeCell alive, retain the current CPU pin, and invoke deactivate_pinned exactly once before another scope is installed or the cell can be dropped. The scheduler must run both hooks while holding its switch baton.

Source

pub unsafe fn deactivate_pinned(&self, pin: &CpuPin<'_>)

Clears this scope from the pinned CPU and retires its active identity.

§Safety

The current CPU must own exactly one activation previously established by try_activate_pinned for this cell.

Source

pub unsafe fn try_with_active_mut_pinned<R>( &self, pin: &CpuPin<'_>, operation: impl for<'scope> FnOnce(&'scope mut ScopeCellWriteGuard<'_>) -> R, ) -> Result<R, ScopeCellBusy>

Mutates the calling task’s active scope.

The active shared lease is atomically upgraded to the writer state and restored before this function returns. A remote reader or a second CPU activation returns ScopeCellBusy instead of making the caller spin.

§Safety

This cell must have exactly one activation, owned by the current CPU, and pin must remain valid for the complete call. The caller must prevent reentrant scope-local access while operation runs.

Trait Implementations§

Source§

impl Default for ScopeCell

Source§

fn default() -> Self

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

impl Drop for ScopeCell

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. 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<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 = !

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

fn try_from(value: U) -> Result<T, !>

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.