Skip to main content

TaskQueue

Struct TaskQueue 

pub struct TaskQueue<const ALLOW_UNBOUND: bool = false> { /* private fields */ }
Expand description

与所属域(owner domain)绑定的内部任务队列(internal task queue),仅在所属线程访问。 队列不可跨线程移动或共享。

默认构造只接收同所属域的任务(Task)。选择 true 时尾插可接收未绑定任务, 头插和整批追加仍要求同所属域。持有任务不建立接纳(admission)或改变其所属域。

Implementations§

§

impl TaskQueue<false>

pub fn new(owner: &TaskThread) -> Self

建立与当前所属域绑定的空队列(queue);不接纳或执行任务(Task)。

§

impl<const ALLOW_UNBOUND: bool> TaskQueue<ALLOW_UNBOUND>

pub fn owner_id(&self) -> TaskOwnerId

取得不可更换的所属域身份,O(1)。

§

impl<const ALLOW_UNBOUND: bool> TaskQueue<ALLOW_UNBOUND>

pub fn len(&self) -> usize

查询本队列当前精确数量,O(1),不含外部队列及执行中任务。

§

impl<const ALLOW_UNBOUND: bool> TaskQueue<ALLOW_UNBOUND>

pub fn is_empty(&self) -> bool

只判断本地是否无节点,不证明运行时(runtime)可以结束。

§

impl<const ALLOW_UNBOUND: bool> TaskQueue<ALLOW_UNBOUND>

pub fn push_front(&mut self, task: Runnable) -> Result<(), QueuePushError>

将本地任务放到队首,影响下一次选择,不打断当前轮询(poll)。 失败返还原值;不隐式接纳到执行器(executor)。 关闭后优先返回Closed,O(1)且不访问节点(node)或执行原值。

§

impl<const ALLOW_UNBOUND: bool> TaskQueue<ALLOW_UNBOUND>

pub fn pop_front(&mut self) -> Option<Runnable>

从队首取出唯一可执行持有;空时None,不轮询(poll)。

§

impl<const ALLOW_UNBOUND: bool> TaskQueue<ALLOW_UNBOUND>

pub fn push_back(&mut self, task: Runnable) -> Result<(), QueuePushError>

将任务(Task)放到队尾。挂起(Pending)后重新唤醒可使用此入口。 TaskQueue<true> 还允许未绑定原值。失败返还原值,保持原接纳(admission)状态。 关闭后优先返回Closed,O(1)且不访问节点(node)或执行原值。

§

impl<const ALLOW_UNBOUND: bool> TaskQueue<ALLOW_UNBOUND>

pub fn pop_back(&mut self) -> Option<Runnable>

从队尾取出唯一可执行持有;空时None,不轮询(poll)。

§

impl<const ALLOW_UNBOUND: bool> TaskQueue<ALLOW_UNBOUND>

pub fn append_batch( &mut self, batch: TaskBatch, ) -> Result<usize, BatchPushError>

把外部单次获取的有序批次完整追加到队尾,返回追加数量。 先完整预检查;失败返回原批次,不留下部分成功前缀。O(n),不等待新增任务。 关闭后优先返回Closed,保留完整原批次(TaskBatch)及顺序;此路径O(1)。

§

impl<const ALLOW_UNBOUND: bool> TaskQueue<ALLOW_UNBOUND>

pub fn drain(&mut self) -> TaskBatch

按队首顺序取回全部当前持有,返回批次;不执行或自动取消它们。

§

impl<const ALLOW_UNBOUND: bool> TaskQueue<ALLOW_UNBOUND>

pub fn clear(&mut self) -> Result<QueueCleanupProgress>

在队列(queue)内部清理当前全部持有,保持接收的开放/关闭标记,不轮询(poll)。

在所属线程(owner thread)通过排他借用同步完成;无并发提交扩展本次范围。 不返回待清理批次(TaskBatch),按原Runnable的合法释放(drop)路径处理; Complete不保证原异步计算(Future)已确认析构(drop)。 无新增内容时重复调用不重复释放;O(n)处理当前数量,不等待其它线程(thread)。 本地实现当前无可恢复错误;分配或原有操作的恐慌(panic)不转换为伪成功。

§

impl<const ALLOW_UNBOUND: bool> TaskQueue<ALLOW_UNBOUND>

pub fn close(&mut self) -> Result<QueueCleanupProgress>

永久停止压入,再按clear内部处理全部当前持有;幂等(idempotent),不重新开放。

push_front、push_back、append_batch从停收后返还原值和Closed分类。 已有弹出、drain及析构(Drop)仍处理余项,不因停收跳过清理。 返回语义、所属线程(owner thread)及成本同clear;若清理异常,停收标记仍保持。 完成只确认本队列(queue)的责任结束/合法移交,不确认任务(Task)取消成功或全部退出。

§

impl TaskQueue<true>

pub fn new_with_unbound(owner: &TaskThread) -> Self

建立开放的空队列,允许从队尾接收未绑定或属于 owner 的原任务(Task)。

头插和整批追加仍要求同所属域。队列由 owner 的所属线程(owner thread)独占使用。

Trait Implementations§

§

impl<const ALLOW_UNBOUND: bool> Drop for TaskQueue<ALLOW_UNBOUND>

§

fn drop(&mut self)

归还所有队列持有并正常释放;不遗留节点内自持有环,不直接推进业务原值。

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
§

impl<const ALLOW_UNBOUND: bool> InternalTaskQueue for TaskQueue<ALLOW_UNBOUND>

§

fn try_push_internal_back( &mut self, task: Runnable, ) -> Result<(), QueuePushError>

沿 TaskQueue::push_back 的接收和拒绝条件。

§

fn try_push_internal_front( &mut self, task: Runnable, ) -> Result<(), QueuePushError>

成功把原值放在下次取得的位置;拒绝时原值和顺序保持。
§

fn pop_internal_front(&mut self) -> Option<Runnable>

取回队首原值一次;空时为 None,无额外接纳(admission)。
§

fn internal_len(&self) -> usize

本次查询时队列实际持有的原值数量。
§

fn internal_owner_id(&self) -> Option<TaskOwnerId>

已预绑定的所属域;None 表示本实现没有预绑定。
§

fn is_internal_closed(&self) -> bool

是否已永久停止接收;不据此推断清理已完成。
§

fn clear_internal(&mut self) -> Result<QueueCleanupProgress>

清理当前范围并返回真实进度,保留原开放或关闭状态。原值析构(drop)的恐慌(panic)沿原责任传播。 完成只确认本队列的持有已清理或合法移交。
§

fn close_internal(&mut self) -> Result<QueueCleanupProgress>

先永久停收再清理。处理失败仍维持停收,未结清持有继续由队列负责。 返回的进度只描述本队列的责任。

Auto Trait Implementations§

§

impl<const ALLOW_UNBOUND: bool = false> !RefUnwindSafe for TaskQueue<ALLOW_UNBOUND>

§

impl<const ALLOW_UNBOUND: bool = false> !Send for TaskQueue<ALLOW_UNBOUND>

§

impl<const ALLOW_UNBOUND: bool = false> !Sync for TaskQueue<ALLOW_UNBOUND>

§

impl<const ALLOW_UNBOUND: bool = false> !UnwindSafe for TaskQueue<ALLOW_UNBOUND>

§

impl<const ALLOW_UNBOUND: bool> Forget for TaskQueue<ALLOW_UNBOUND>

§

impl<const ALLOW_UNBOUND: bool> Freeze for TaskQueue<ALLOW_UNBOUND>

§

impl<const ALLOW_UNBOUND: bool> Move for TaskQueue<ALLOW_UNBOUND>

§

impl<const ALLOW_UNBOUND: bool> Unpin for TaskQueue<ALLOW_UNBOUND>

§

impl<const ALLOW_UNBOUND: bool> UnsafeUnpin for TaskQueue<ALLOW_UNBOUND>

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.