pub struct LevelCore { /* private fields */ }Expand description
The core’s runtime, shared by every level of the image. Copy: each
level’s thread carries the handle.
Implementations§
Source§impl LevelCore
impl LevelCore
Sourcepub unsafe fn new(
runtime: ExecutorNodeRuntime,
n_levels: u8,
boot_level: u8,
mutex: *mut c_void,
lock: ExecLockFn,
unlock: ExecLockFn,
thread_id: ThreadIdFn,
) -> Result<Self, LevelError>
pub unsafe fn new( runtime: ExecutorNodeRuntime, n_levels: u8, boot_level: u8, mutex: *mut c_void, lock: ExecLockFn, unlock: ExecLockFn, thread_id: ThreadIdFn, ) -> Result<Self, LevelError>
Make runtime the core’s level runtime (leaked for the image’s life).
n_levels is the image’s level count and boot_level the level of
the calling thread. With more than one level, mutex must be an
initialised recursive priority-inheriting mutex that lock / unlock
take and give and thread_id must name the calling thread: the
executor carries them so every pass releases the lock around its
callbacks and the levels preempt each other on one executor.
§Safety
Called before any second thread can reach the runtime. mutex lives
for the image’s life; thread_id is equal on one thread and distinct
across live threads.
Sourcepub unsafe fn with_runtime<R>(
&self,
f: impl FnOnce(&mut ExecutorNodeRuntime) -> R,
) -> R
pub unsafe fn with_runtime<R>( &self, f: impl FnOnce(&mut ExecutorNodeRuntime) -> R, ) -> R
Run f on the core’s runtime with the lock held.
§Safety
No reference to the runtime obtained here outlives f.
Sourcepub unsafe fn open_level(
&self,
level: u8,
) -> Result<&'static mut BandWorker, LevelError>
pub unsafe fn open_level( &self, level: u8, ) -> Result<&'static mut BandWorker, LevelError>
Open level level on the calling thread: its worker (leaked with the
level) attached to the executor’s arrival routing and the level made
the registering one. Returns the worker the thread’s passes use.
§Safety
Called once per level, on the level’s own thread.
Sourcepub unsafe fn spin_level_once(
&self,
worker: &mut BandWorker,
timeout: Duration,
) -> SpinOnceResult
pub unsafe fn spin_level_once( &self, worker: &mut BandWorker, timeout: Duration, ) -> SpinOnceResult
One pass of a spawned level’s worker: it parks (its waiter, the lock
released) for at most timeout or until its band’s next timer or an
arrival, then runs its band’s ready callbacks and (issue 2020) the
ticks of the components its level registered – the executor’s
enrolled ones inside the band pass, the runtime’s own after it, the
lock held. Returns the pass’s counts.
§Safety
worker is the calling thread’s, from Self::open_level.
Sourcepub unsafe fn into_runtime(self) -> ExecutorNodeRuntime
pub unsafe fn into_runtime(self) -> ExecutorNodeRuntime
Issue 2016 – the teardown: take the runtime back from the levels,
the executor’s lock removed, for the caller to close its session
(Executor::close) and drop it. The level workers stay leaked, as
they were for the image’s life, and the level count stays stated.
§Safety
Called once, on the boot level’s thread, after every other thread
that reached the runtime (each level’s worker, any callback it ran)
has stopped and been joined; no copy of this LevelCore is used
afterwards.
Sourcepub unsafe fn entry_spin_budget(&self) -> Duration
pub unsafe fn entry_spin_budget(&self) -> Duration
phase-521 W6 (RFC-0113 D2) – the budget a level runner passes to
Self::spin_level_once / Self::spin_boot_once: the runtime’s
ExecutorNodeRuntime::entry_spin_budget. Each park already ends at
the level’s next deadline or on an arrival, so the budget is not a
cadence; passing the tier’s period instead woke every idle level once a
period. Ask it after the levels’ setup, which is what registers the
components whose ticks keep the short budget.
§Safety
Sourcepub fn wake_all(&self)
pub fn wake_all(&self)
phase-521 W6 – wake every level’s worker and the boot level, for a runner that is stopping them: a level parked on the long budget would otherwise see its stop flag only at its next deadline. Lock-free.
Sourcepub unsafe fn spin_boot_once(&self, timeout: Duration) -> SpinOnceResult
pub unsafe fn spin_boot_once(&self, timeout: Duration) -> SpinOnceResult
One pass of the boot level: the executor’s own worker (transport, executor-wide chores), then the boot level’s components’ ticks, the lock held except around each callback.
§Safety
Called from the boot level’s thread only.