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
impl ScopeCell
Sourcepub fn from_scope(scope: Scope) -> Self
pub fn from_scope(scope: Scope) -> Self
Wraps an existing scope with a managed scheduler binding.
Sourcepub fn try_read(&self) -> Result<ScopeCellReadGuard<'_>, ScopeCellBusy>
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.
Sourcepub fn try_write(&self) -> Result<ScopeCellWriteGuard<'_>, ScopeCellBusy>
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.
Sourcepub unsafe fn try_activate_pinned(
&self,
pin: &CpuPin<'_>,
) -> Result<(), ScopeActivationError>
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.
Sourcepub unsafe fn deactivate_pinned(&self, pin: &CpuPin<'_>)
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.
Sourcepub unsafe fn try_with_active_mut_pinned<R>(
&self,
pin: &CpuPin<'_>,
operation: impl for<'scope> FnOnce(&'scope mut ScopeCellWriteGuard<'_>) -> R,
) -> Result<R, ScopeCellBusy>
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.