pub enum Executor {
Pool(ThreadPool),
Delegating(DelegatingExecutor),
}Expand description
一个执行器。
用 enum 而不是 Box<dyn Executor>:dispatch_task 在热路径上
(schedule_node 的 while try_claim 每轮都调一次),静态分发省掉虚表;
而且「关停 + join 必须发生在动节点之前」这条约定要看得清具体类型。
Variants§
Pool(ThreadPool)
拥有自己工作线程的线程池(YAML type: "ThreadPoolExecutor")。
Delegating(DelegatingExecutor)
不拥有线程,交还宿主线程(YAML type: "DelegatingExecutor")。
Implementations§
Source§impl Executor
impl Executor
pub fn name(&self) -> &str
Sourcepub fn is_delegating(&self) -> bool
pub fn is_delegating(&self) -> bool
是否把任务交还宿主线程(而不是自有工作线程)。
Sourcepub fn num_threads(&self) -> usize
pub fn num_threads(&self) -> usize
自有工作线程数。委托执行器返回 0 —— 它一个线程都不拥有。
Sourcepub fn start(&self, graph: Weak<GraphInner>)
pub fn start(&self, graph: Weak<GraphInner>)
拉起工作线程。委托执行器是 no-op:宿主线程早就在跑,不由引擎创建。
pub fn submit_source_wake( &self, node: NodeId, generation: u64, delay: Duration, ) -> bool
pub fn pending(&self) -> usize
Sourcepub fn take_delegated(&self) -> Option<NodeId>
pub fn take_delegated(&self) -> Option<NodeId>
弹一个待宿主执行的任务;线程池恒返回 None(它的任务由自己的 worker 取)。
pub fn complete_delegated(&self, execution: Option<Duration>)
Sourcepub fn clear_delegated(&self)
pub fn clear_delegated(&self)
清空待宿主执行的队列(reset 用);线程池是 no-op。
pub fn reset_run_state(&self)
pub fn clear_delayed(&self)
Auto Trait Implementations§
impl !Freeze for Executor
impl RefUnwindSafe for Executor
impl Send for Executor
impl Sync for Executor
impl Unpin for Executor
impl UnsafeUnpin for Executor
impl UnwindSafe for Executor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more