Skip to main content

DefaultExecutor

Struct DefaultExecutor 

pub struct DefaultExecutor<C, E, I, T, L, Q = TaskQueue>
where C: ExecutorClock, E: ExternalBinding, I: IdleBinding, T: TimerBinding<ClockInstant = C::Instant>, L: LocalReadySubmit, Q: InternalTaskQueue,
{ /* private fields */ }
Expand description

供运行时(runtime)实现者静态组合的完整机制;本对象!Send/!Sync,不创建线程。 外部提供当前线程,创建后固定所属域。公开业务由更外层简洁类型包装,不暴露类型链。 释放(drop)停止接纳并交还原来源与本地任务(Task)责任;仍存活动可延迟本地实际退出。 上层运行时(runtime)须先撤本地权限;共享访问晚释放不成为原异步计算(Future)清理前提。 清理失败保持已关闭不可用与未完成确认,不重新执行原值或报告成功完成。

内部任务队列(internal task queue)默认使用 TaskQueue。选配的具体队列 Q 由同一 所属线程(owner thread)上的本地设施独占,原共享句柄(shared handle)可以跨线程使用。

Implementations§

§

impl<C, E, I, T, L> DefaultExecutor<C, E, I, T, L>

pub fn new( clock: C, external: E, idle: I, options: ExecutorOptions, make_timer: impl FnOnce(RuntimeId, &C, ThreadNotifier) -> Result<T>, ) -> Result<Self>

接管新建的私有普通/空闲管理对象,在本线程新建原所属域。 make_timer取得最终RuntimeId、同一clock及原线程通知,必须返回同源新拥有者。 原来源应未公开业务访问;构造失败合法释放已接管资源,不初始化全局时钟。

Examples found in repository?
examples/executor_bounds.rs (lines 41-47)
39fn declarations(clock: ManualClock, external: MpscTaskQueue, idle: MpscIdleTaskQueue) {
40    send_sync::<Shared>();
41    let _: pi_result::Result<Service> = Service::new(
42        clock,
43        external,
44        idle,
45        ExecutorOptions::default(),
46        |id, clock, notify| Timer::new(id, *clock, notify, CancelTimerOptions::default()),
47    );
48}
§

impl<C, E, I, T, L, Q> DefaultExecutor<C, E, I, T, L, Q>

pub fn with_internal_queue( clock: C, external: E, idle: I, internal: Q, options: ExecutorOptions, make_timer: impl FnOnce(RuntimeId, &C, ThreadNotifier) -> Result<T>, ) -> Result<Self>

按值移交现成的内部任务队列(internal task queue),由本执行器独占。

队列须开放且为空。已预绑定的队列必须匹配本执行器的所属域(owner domain)。 依赖该所属域构造的队列可使用 Self::with_internal_queue_factory。 自定义队列须按原约定精确交接和记数,保证已接纳任务(Task)可以重新入队。 成功入队后须正常返回。构造检查早于定时构造回调。

正常进入本地关闭(close)时调用一次 close_internal。若返回 MoreWork, 当前推进报告清理未确认,由原队列的析构(drop)接续余项。直接返回的错误 按原首错顺序归还。所属域仍被活动借用时,调用报告未确认,由合法退出接续析构。 自定义队列析构时须结束本队列的服务并结清未移交的原任务。

§Errors

队列已关闭、非空或属于另一所属域时返回 InvalidInput。已移交的资源 由本次构造负责释放,定时构造和其它来源仍适用 DefaultExecutor::new 的约定。

pub fn with_internal_queue_factory( clock: C, external: E, idle: I, make_internal: impl for<'owner> FnOnce(InternalQueueContext<'owner>) -> Result<Q>, options: ExecutorOptions, make_timer: impl FnOnce(RuntimeId, &C, ThreadNotifier) -> Result<T>, ) -> Result<Self>

建立所属域(owner domain)后,调用一次构造回调(callback)取得内部任务队列。

回调只在本次构造期间取得 InternalQueueContext。返回的队列须满足 Self::with_internal_queue 的条件及关闭(close)约定。队列检查成功后才调用定时构造回调。

§Errors

构造回调的错误按原报告返回。回调返回不符合条件的队列时返回 InvalidInput。

§

impl<C, E, I, T, L> DefaultExecutor<C, E, I, T, L>
where C: ExecutorClock, E: ExternalQueueManager, I: IdleBinding, T: TimerBinding<ClockInstant = C::Instant>, L: LocalReadySubmit,

pub fn with_queues( clock: C, external: E, idle: I, options: ExecutorOptions, make_timer: impl MakeTimer<C, T>, ) -> Result<Self>

组合外部任务队列(external task queue)、默认内部任务队列(internal task queue) 和可选的定时任务队列(timer task queue)、空闲任务队列(idle task queue)。

传入 crate::NoIdleQueue 省略空闲来源;传入 crate::NoTimerQueue::default 省略定时来源,也可以传入定时构造回调(callback)。队列组合由具体类型确定。 省略的来源不开放相应的派发方法。配置定时时,使用 DefaultExecutor::new 的时钟(clock) 和同源身份约定。省略定时时不采样时钟。 构造错误返还原报告,已移交的资源沿原退出顺序清理。

§

impl<C, E, I, T, L, Q> DefaultExecutor<C, E, I, T, L, Q>
where C: ExecutorClock, E: ExternalQueueManager, I: IdleBinding, T: TimerBinding<ClockInstant = C::Instant>, L: LocalReadySubmit, Q: InternalTaskQueue,

pub fn with_queue_factories( clock: C, external: E, idle: I, make_internal: impl for<'owner> FnOnce(InternalQueueContext<'owner>) -> Result<Q>, options: ExecutorOptions, make_timer: impl MakeTimer<C, T>, ) -> Result<Self>

在 Self::with_queues 可选队列的组合中,由回调(callback)取得内部任务队列。

回调(callback)按值交入已准备的队列,或使用短期 InternalQueueContext 构造。 检查开放、空队列和原所属域(owner domain),然后才构造定时来源。关闭(close) 沿 Self::with_internal_queue_factory 的内部任务队列约定。

§

impl<C, E, I, T, L, Q> DefaultExecutor<C, E, I, T, L, Q>
where C: ExecutorClock, E: ExternalBinding, I: IdleBinding, T: TimerBinding<ClockInstant = C::Instant>, L: LocalReadySubmit, Q: InternalTaskQueue,

pub fn handle(&self) -> ExecutorHandle<E::Handle, I::Handle, T, L>

pub fn local(&self) -> &Rc<ExecutorLocal<T, Q>>

框架本地权限注册目标,只供运行时(runtime)装配;最终业务不得取得它。

pub fn begin_drive(&self) -> DriveLease

核当前线程并独占标记;重复推进在用户Future首次poll前panic。 本函数不进入全局DriveScope,供block_on核心自身统一建立该范围。

pub fn run_once<A: AdmissionRule, P: IdlePolicy, H: ExecutorHooks>( &mut self, admission: &A, policy: &mut P, hooks: &mut H, ) -> Result<TurnResult>
where E: ExternalAdmission<A>,

一次有限轮转,不停放线程、不等新任务。用户Future、Drop或控制hook可同步阻塞。 最多One到期/内部/空闲各一次业务run机会;有限批次直接清理另算。 All到期业务按序转内部,不逐项内联poll;已取消/退出者不隐式admit。 浏览器(browser)由所属线程(owner thread)的宿主回调(callback)调用。 每轮结束后把控制权交回宿主,根据 TurnResult 和应用事件安排下一轮。

pub fn run<A: AdmissionRule, P: IdlePolicy, H: ExecutorHooks>( &mut self, admission: &A, policy: &mut P, hooks: &mut H, ) -> Result<()>
where E: ExternalAdmission<A>,

持续推进至服务关闭;外部提交、已有唤醒、取消/关闭及超时均可使停放返回。 需要宿主支持线程休眠。浏览器(browser)请用 Self::run_once。

pub fn turn_with_lease<A: AdmissionRule, P: IdlePolicy, H: ExecutorHooks>( &mut self, lease: &DriveLease, admission: &A, policy: &mut P, hooks: &mut H, ) -> Result<TurnResult>
where E: ExternalAdmission<A>,

已合法取得本次DriveLease的内部轮转;不再次进入DriveScope,不为block_on制造嵌套。

pub fn park_with_lease<A: AdmissionRule>( &mut self, lease: &DriveLease, admission: &A, last: &TurnResult, root: Option<&RootWakeState>, ) -> Result<()>
where E: ExternalAdmission<A>,

用上次策略建议重新核工作、通知与定时上界;root仅用于同步根的额外通知。 返回前若通知已消费必须实际重新轮询,不能以旧snapshot继续停放。

Trait Implementations§

§

impl<C, E, I, T, L, Q> Drop for DefaultExecutor<C, E, I, T, L, Q>
where C: ExecutorClock, E: ExternalBinding, I: IdleBinding, T: TimerBinding<ClockInstant = C::Instant>, L: LocalReadySubmit, Q: InternalTaskQueue,

§

fn drop(&mut self)

Executes the destructor for this type. Read more
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

Auto Trait Implementations§

§

impl<C, E, I, T, L, Q = TaskQueue> !RefUnwindSafe for DefaultExecutor<C, E, I, T, L, Q>

§

impl<C, E, I, T, L, Q = TaskQueue> !Send for DefaultExecutor<C, E, I, T, L, Q>

§

impl<C, E, I, T, L, Q = TaskQueue> !Sync for DefaultExecutor<C, E, I, T, L, Q>

§

impl<C, E, I, T, L, Q = TaskQueue> !UnwindSafe for DefaultExecutor<C, E, I, T, L, Q>

§

impl<C, E, I, T, L, Q> Forget for DefaultExecutor<C, E, I, T, L, Q>

§

impl<C, E, I, T, L, Q> Freeze for DefaultExecutor<C, E, I, T, L, Q>
where C: Freeze, Option<E>: Freeze, <I as IdleOwnerOperations>::Owner: Freeze, Rc<ExecutorLocal<T, Q>>: Freeze, ExecutorHandle<<E as ExternalBinding>::Handle, <I as IdleBinding>::Handle, T, L>: Freeze,

§

impl<C, E, I, T, L, Q> Move for DefaultExecutor<C, E, I, T, L, Q>

§

impl<C, E, I, T, L, Q> Unpin for DefaultExecutor<C, E, I, T, L, Q>
where C: Unpin, Option<E>: Unpin, <I as IdleOwnerOperations>::Owner: Unpin, Rc<ExecutorLocal<T, Q>>: Unpin, ExecutorHandle<<E as ExternalBinding>::Handle, <I as IdleBinding>::Handle, T, L>: Unpin,

§

impl<C, E, I, T, L, Q> UnsafeUnpin for DefaultExecutor<C, E, I, T, L, Q>
where C: UnsafeUnpin, Option<E>: UnsafeUnpin, <I as IdleOwnerOperations>::Owner: UnsafeUnpin, Rc<ExecutorLocal<T, Q>>: UnsafeUnpin, ExecutorHandle<<E as ExternalBinding>::Handle, <I as IdleBinding>::Handle, T, L>: UnsafeUnpin,

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.