pub(crate) struct Context {
worker: Arc<Worker>,
core: RefCell<Option<Box<Core>>>,
pub(crate) defer: Defer,
}
Expand description
Thread-local context
Fields§
§worker: Arc<Worker>
Worker
core: RefCell<Option<Box<Core>>>
Core data
defer: Defer
Tasks to wake after resource drivers are polled. This is mostly to handle yielded tasks.
Implementations§
source§impl Context
impl Context
fn run(&self, core: Box<Core>) -> Result<Box<Core>, ()>
fn run_task( &self, task: Notified<Arc<Handle>>, core: Box<Core>, ) -> Result<Box<Core>, ()>
fn reset_lifo_enabled(&self, core: &mut Core)
fn assert_lifo_enabled_is_correct(&self, core: &Core)
fn maintenance(&self, core: Box<Core>) -> Box<Core>
sourcefn park(&self, core: Box<Core>) -> Box<Core>
fn park(&self, core: Box<Core>) -> Box<Core>
Parks the worker thread while waiting for tasks to execute.
This function checks if indeed there’s no more work left to be done before parking.
Also important to notice that, before parking, the worker thread will try to take
ownership of the Driver (IO/Time) and dispatch any events that might have fired.
Whenever a worker thread executes the Driver loop, all waken tasks are scheduled
in its own local queue until the queue saturates (ntasks > LOCAL_QUEUE_CAPACITY
).
When the local queue is saturated, the overflow tasks are added to the injection queue
from where other workers can pick them up.
Also, we rely on the workstealing algorithm to spread the tasks amongst workers
after all the IOs get dispatched