Skip to main content

DefaultTimerDriver

Struct DefaultTimerDriver 

pub struct DefaultTimerDriver<C, L>{ /* private fields */ }
Expand description

默认定时接入的唯一线程内驱动(driver),!Send+!Sync,不克隆管理责任。

原生来源使用pi_cancel_timer 0.7,由已冻结队列实现维护;本对象仅连接核心登记和取消重试。 每次advance只消费显式同源时刻;时钟由执行器统一取得,不由队列刷新。 普通业务运行时(runtime)不导出本对象、原生句柄或LocalTimerHandle。 精度及范围沿CancelTimerQueue:1ms,推进向下取整、截止向上取整,不提前交付; 截止为同一起点后0至18,446,744,073,709,000,000ns,参考时刻可达GlobalManualInstant::MAX。 完整到期批次保持当前范围实际发现顺序,空间和处理成本随批次增大,不承诺固定开销。 释放(drop)请求退场;正在执行的本地同步活动可延迟实际清理,不等待外部共享句柄释放才清理原值。

Implementations§

§

impl<C, L> DefaultTimerDriver<C, L>

pub fn new( runtime: RuntimeId, clock: C, notifier: ThreadNotifier, options: CancelTimerOptions, ) -> Result<Self>

在当前线程创建独立来源,真实取同一clock一次作为初始参考;不初始化pi_clock。 同时准备一份接续stub,默认重试工作额度复用options.work_batch_size。

Examples found in repository?
examples/executor_bounds.rs (line 46)
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}
More examples
Hide additional examples
examples/timer_bounds.rs (line 37)
33fn declarations(id: RuntimeId, clock: ManualClock, notifier: ThreadNotifier) {
34    send_sync::<DefaultTimerAccess<ManualClock, Route>>();
35    send_sync::<DefaultTimerRegistration<ManualClock, Route>>();
36    send::<DefaultTimerItem<ManualClock, Route>>();
37    let _ = DefaultTimerDriver::<_, Route>::new(id, clock, notifier, CancelTimerOptions::default());
38}

pub fn from_queue( runtime: RuntimeId, clock: C, notifier: ThreadNotifier, queue: CancelTimerQueue<DefaultTimerItem<C, L>, ThreadNotifier>, ) -> Result<Self>

接管当前线程已准备的原定时任务队列(timer task queue)。 实例须开放,并使用原执行器(executor)的时间域(time domain)和线程通知句柄(ThreadNotifier)。 首次公开共享访问前核对配对。失败保留原报告(Report),由实际拥有者(owner)释放已接管资源。

pub fn local_handle(&self) -> LocalTimerHandle<C, L>

返回仅本线程可用的同源Weak访问;不增加长期原生拥有者。

Trait Implementations§

§

impl<C, L> Drop for DefaultTimerDriver<C, L>

§

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
§

impl<C, L> ExecutorTimer for DefaultTimerDriver<C, L>

§

type Access = DefaultTimerAccess<C, L>

§

fn timer_access(&self) -> Self::Access

§

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

在普通定时推进前有限处理预备取消节点;不分配每次重试,不等待键或其它发布者。
§

impl<C, L> TimerTaskQueue for DefaultTimerDriver<C, L>

§

fn try_push_local( &mut self, deadline: Self::Instant, item: Self::Item, ) -> RawResult<Self::Key, TimerSubmitError<Self::Item>>

在原所属线程(owner thread)提交同源原值,不附加Send/Sync;拒绝返还同一原值及原因。 成功只确认来源接收,不轮询(poll)或隐式接纳;已接收后的退场不倒退为提交拒绝。

§

fn advance( &mut self, now: &Self::Instant, ) -> RawResult<TimerAdvanceProgress, TimerQueueError>

以显式同源时刻有限推进,不刷新或替换时间轴;时间倒退返回原InvalidTime。 ReachedTarget只表示追时位置,不证明所有到期项均已发现。

§

fn try_take_due_all( &mut self, ) -> RawResult<TimerTake<Self::DueBatch>, TimerQueueError>

完整交付本次固定范围内全部可业务交付的到期原值,保留来源发现顺序,可能超过普通工作额度。 尚不能确认完整返回WouldBlock并保管原值;下次重试重新确定范围,不以部分向量冒充全部。

§

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

有限处理来源清理及取消接续,不以是否到期或空闲决定是否清理。 移交此前无返回口保留的首份原错误;MoreWork或错误不解除剩余责任,纯查询不取走该错误。

§

fn next_check_at( &self, now: &Self::Instant, ) -> RawResult<Option<Self::Instant>, TimerQueueError>

只读返回最迟再次检查时刻。仅读取提供的参考时刻和来源状态,取时、推进和通知由其它入口负责。 原生错误原样返回,原生时刻最早为 now。 存在待结清的取消接续时,使用 now + 1ms(饱和于 MAX)和原生时刻中较早者。 原生无时刻时直接使用该保守时刻。没有观察到待结清项时,沿用原生结果。 原生有登记或管理未完不晚于 now + 1ms,开放空来源不晚于 now + 10ms。 原生来源无后续检查且未观察到待结清项时返回 None,关闭完成以清理结果为准。 继续使用主动通知和休眠前重查。

§

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

永久停收并推进来源与取消接续的退出;重复调用幂等(idempotent),用于整体服务关闭。 Complete须两部分责任均结束且没有待报告错误;活动中的本地操作保有实际退出责任。 不表示业务原异步计算(Future)已全部成功析构,不支持关闭计时后继续正常服务的稳态。

§

type Item = TimerEntry<CancelTimerKey, DefaultTimerRegistration<C, L>>

原登记内容,可为可执行句柄(Runnable)或计时登记;不要求额外封装新任务(Task)。
§

type Instant = GlobalManualInstant

同一时钟实例、起点和单位下的绝对时刻;构造和实现负责其关联及比较。 不要求复制或全序比较,不指定为整数或标准库(standard library)时刻。
§

type Key = CancelTimerKey

原登记的不透明键(opaque key),不强制可复制(Copy)或可克隆(Clone)。 正常释放不取消;内部移动保持身份,过期或错误来源不能命中另一登记。
§

type DueBatch = Vec<<DefaultTimerDriver<C, L> as TimerTaskQueue>::Item>

独立拥有的有限到期序列;迭代不回访来源,不吸收新内容,不携带队列(queue)保护。
§

type Handle = CancelTimerQueueHandle<<DefaultTimerDriver<C, L> as TimerTaskQueue>::Item, ThreadNotifier>

同一原来源的受限共享入口;类型(type)匹配不单独证明实例匹配。
§

fn handle(&self) -> Self::Handle

取得同一原来源的共享句柄(shared handle),不新建队列(queue)或重置状态(state)。 不强制使用Arc或进行分配;取得/释放句柄(handle)本身不取消登记。
§

fn request_cancel_local( &mut self, key: &Self::Key, ) -> RawResult<(), TimerCancelRequestError>

本地同步记录或合并key的取消请求(cancellation request),不消费键(key)。 Read more
§

fn try_take_due_one( &mut self, ) -> RawResult<TimerTake<Self::Item>, TimerQueueError>

最多交出一份可交付到期原值,不等待其它到期项发现或后来提交。 不读取另一时钟,使用已有显式推进依据。 Ready取得原值及后续责任;不保证本次已经发现全部到期内容。
§

fn status(&self) -> TimerQueueStatus

查询来源状态快照(snapshot),不推进计时或业务;不与另一次数量读取组成全局瞬间。
§

fn len(&self) -> usize

查询已接收、尚未交出/实际清理的全部登记数。 包含共享中转、原生存储、到期及待清理缓冲;内部移动或取消标记不减数。 实际交付/清理恰减一次,不包含已经交给执行器(executor)的在途任务(in-flight task)。
§

fn is_empty(&self) -> bool

按len相同口径取得是否为零的样本,不证明关闭完成或下一次取出结果。
§

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

有限清理本次固定范围,不关闭接收,不要求到期,不业务轮询(poll)。 Read more

Auto Trait Implementations§

§

impl<C, L> !RefUnwindSafe for DefaultTimerDriver<C, L>

§

impl<C, L> !Send for DefaultTimerDriver<C, L>

§

impl<C, L> !Sync for DefaultTimerDriver<C, L>

§

impl<C, L> !UnwindSafe for DefaultTimerDriver<C, L>

§

impl<C, L> Forget for DefaultTimerDriver<C, L>

§

impl<C, L> Freeze for DefaultTimerDriver<C, L>
where Rc<TimerLocalCore<C, L>>: Freeze,

§

impl<C, L> Move for DefaultTimerDriver<C, L>

§

impl<C, L> Unpin for DefaultTimerDriver<C, L>
where Rc<TimerLocalCore<C, L>>: Unpin,

§

impl<C, L> UnsafeUnpin for DefaultTimerDriver<C, L>
where Rc<TimerLocalCore<C, 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.