pub struct Context<TTask> {
pub Identifier: usize,
pub Local: (Worker<TTask>, Worker<TTask>, Worker<TTask>),
pub Share: Arc<Share<TTask>>,
}Expand description
Contains all necessary components for a single worker thread to operate.
This includes the thread-local Worker deques, which are not safe to share,
making this Context object the sole owner of a worker’s private queues.
Fields§
§Identifier: usizeA unique identifier for the worker, used to avoid self-stealing.
Local: (Worker<TTask>, Worker<TTask>, Worker<TTask>)Thread-local work queues for each priority level.
A reference to the shared components of the entire queue system.
Implementations§
Source§impl<TTask> Context<TTask>
impl<TTask> Context<TTask>
Sourcepub fn Next(&self) -> Option<TTask>
pub fn Next(&self) -> Option<TTask>
Finds the next available task for the worker to execute.
This method implements the complete work-finding logic:
- Check local deques (from high to low priority).
- If local deques are empty, attempt to steal from the system (from high to low priority).
Sourcepub fn Steal<'a>(
&self,
Injector: &'a Injector<TTask>,
Stealers: &'a [Stealer<TTask>],
Local: &'a Worker<TTask>,
) -> Option<TTask>
pub fn Steal<'a>( &self, Injector: &'a Injector<TTask>, Stealers: &'a [Stealer<TTask>], Local: &'a Worker<TTask>, ) -> Option<TTask>
Attempts to steal a task from a specific priority set.
It first tries to steal a batch from the global injector queue for that priority. If that fails, it attempts to steal from a randomly chosen peer worker to ensure fair distribution and avoid contention hotspots.