pub struct WorkerService<const P: usize = DEFAULT_QUEUE_SEG_SHIFT, const NUM_SEGS_P2: usize = DEFAULT_QUEUE_NUM_SEGS_SHIFT> { /* private fields */ }Implementations§
Source§impl<const P: usize, const NUM_SEGS_P2: usize> WorkerService<P, NUM_SEGS_P2>
impl<const P: usize, const NUM_SEGS_P2: usize> WorkerService<P, NUM_SEGS_P2>
pub fn start( arena: TaskArena, config: WorkerServiceConfig, tick_service: &Arc<TickService>, ) -> Arc<Self>
Sourcepub fn reserve_task(&self) -> Option<TaskHandle>
pub fn reserve_task(&self) -> Option<TaskHandle>
Reserve a task slot using the SummaryTree.
Sourcepub fn release_task(&self, handle: TaskHandle)
pub fn release_task(&self, handle: TaskHandle)
Release a task slot back to the SummaryTree.
pub fn spawn_worker(&self) -> Result<(), PushError<()>>where
Self: Sized,
pub fn tick_duration(&self) -> Duration
pub fn clock_ns(&self) -> u64
pub fn shutdown(&self)
Sourcepub fn worker_count(&self) -> usize
pub fn worker_count(&self) -> usize
Returns the current worker count
Sourcepub fn worker_has_work(&self, worker_id: usize) -> bool
pub fn worker_has_work(&self, worker_id: usize) -> bool
Checks if a specific worker has any work to do
Sourcepub fn interrupt_worker(
&self,
worker_id: usize,
) -> Result<bool, PreemptionError>
pub fn interrupt_worker( &self, worker_id: usize, ) -> Result<bool, PreemptionError>
Interrupt a specific worker thread to trigger preemptive generator switching.
The worker thread is NOT terminated! It is only briefly interrupted to:
- Pin its current generator to the running task (save stack state)
- Create a new generator for itself
- Continue executing with the new generator
The interrupted task can later be resumed with its pinned generator. This allows true preemptive multitasking at the task level.
Can be called from any thread (e.g., a timer thread).
§Arguments
worker_id- The ID of the worker to interrupt (0-based index)
§Returns
Ok(true)- Worker was successfully interruptedOk(false)- Worker doesn’t exist (invalid ID)Err- Interrupt operation failed (platform error)
Trait Implementations§
Source§impl<const P: usize, const NUM_SEGS_P2: usize> TickHandler for WorkerService<P, NUM_SEGS_P2>
impl<const P: usize, const NUM_SEGS_P2: usize> TickHandler for WorkerService<P, NUM_SEGS_P2>
Source§fn tick_duration(&self) -> Duration
fn tick_duration(&self) -> Duration
Returns the desired tick duration for this handler.
The TickService will use the minimum of all registered handlers’ tick durations.
Source§fn on_tick(&self, tick_count: u64, now_ns: u64)
fn on_tick(&self, tick_count: u64, now_ns: u64)
Called on each tick with the current time in nanoseconds and tick count.
Source§fn on_shutdown(&self)
fn on_shutdown(&self)
Called when the tick service is shutting down.
impl<const P: usize, const NUM_SEGS_P2: usize> Send for WorkerService<P, NUM_SEGS_P2>
impl<const P: usize, const NUM_SEGS_P2: usize> Sync for WorkerService<P, NUM_SEGS_P2>
Auto Trait Implementations§
impl<const P: usize = DEFAULT_QUEUE_SEG_SHIFT, const NUM_SEGS_P2: usize = DEFAULT_QUEUE_NUM_SEGS_SHIFT> !Freeze for WorkerService<P, NUM_SEGS_P2>
impl<const P: usize = DEFAULT_QUEUE_SEG_SHIFT, const NUM_SEGS_P2: usize = DEFAULT_QUEUE_NUM_SEGS_SHIFT> !RefUnwindSafe for WorkerService<P, NUM_SEGS_P2>
impl<const P: usize, const NUM_SEGS_P2: usize> Unpin for WorkerService<P, NUM_SEGS_P2>
impl<const P: usize = DEFAULT_QUEUE_SEG_SHIFT, const NUM_SEGS_P2: usize = DEFAULT_QUEUE_NUM_SEGS_SHIFT> !UnwindSafe for WorkerService<P, NUM_SEGS_P2>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more