Skip to main content

LocalQueue

Struct LocalQueue 

Source
pub struct LocalQueue { /* private fields */ }
Expand description

Local queue for thread-per-core scheduler thread-per-core调度器的本地队列

Uses a bounded ring buffer optimized for single consumer (the scheduler thread) with support for external producers (work stealing injectors). Uses interior mutability for thread-safe operations.

使用为单个消费者(调度器线程)优化的有界环形缓冲区, 支持外部生产者(工作窃取注入器)。 使用内部可变性实现线程安全操作。

Implementations§

Source§

impl LocalQueue

Source

pub fn new(capacity: usize) -> Self

Create a new local queue with the specified capacity 创建具有指定容量的新本地队列

The capacity will be rounded up to the next power of 2. 容量将向上舍入到下一个2的幂。

Source

pub fn push(&self, task: RawTask) -> bool

Push a task to the back of the queue 将任务推入队列后部

Returns true if successful, false if the queue is full. 成功返回 true,队列已满返回 false

Source

pub fn pop(&self) -> Option<RawTask>

Pop a task from the front of the queue 从队列前部弹出一个任务

Returns Some(task) if available, None if the queue is empty. 有可用任务时返回 Some(task),队列为空时返回 None

Source

pub fn len(&self) -> usize

Get the current length of the queue 获取队列当前长度

Source

pub fn is_empty(&self) -> bool

Check if the queue is empty 检查队列是否为空

Source

pub const fn capacity(&self) -> usize

Get the queue capacity 获取队列容量

Source

pub fn steal(&self, dest: &LocalQueue) -> usize

Steal half of the tasks from this queue 从此队列窃取一半任务

Used for work stealing between scheduler threads. 用于调度器线程间的工作窃取。

Returns the number of tasks stolen. 返回被窃取的任务数量。

Trait Implementations§

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.