Struct ConfiguredRuntime
pub struct ConfiguredRuntime<M, C, P, H, E = MpscTaskQueue, I = MpscIdleTaskQueue, T = DefaultTimerDriver<C, RuntimeTag<C>>>where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
P: IdlePolicy,
H: ExecutorHooks,{ /* private fields */ }Expand description
一份固定线程服务,不可Send/Sync;不创建或接管外部线程的所有权。 常规使用SerialRuntime/ConcurrentRuntime,无需填写内部参数;定制类型由with_components推导。 释放(drop)先撤本地权限,再按原执行器(executor)及任务域约定实际退出。 正在进行的同步活动可延迟实际本地清理,不等待普通共享句柄(shared handle)全部释放。 关闭请求、服务不可用与成功完成分别观察,清理失败不能报CloseState::Completed。 waiting_for_wake_count及pending_cancel_task_count沿默认执行器按需O(n)扫描登记,n为登记规模; 封装不把这两项查询转为固定成本,默认推进不主动采集。
Implementations§
§impl<M, C, P, H, E, I, T> ConfiguredRuntime<M, C, P, H, E, I, T>where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
P: IdlePolicy,
H: ExecutorHooks,
impl<M, C, P, H, E, I, T> ConfiguredRuntime<M, C, P, H, E, I, T>where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
P: IdlePolicy,
H: ExecutorHooks,
pub fn submit_local_front(task: UnsubmittedTask) -> RawResult<(), SubmitError>
pub fn submit_local_front(task: UnsubmittedTask) -> RawResult<(), SubmitError>
由当前原线程把首次提交放内部头;无本地权限时返原值及原因。
pub fn spawn_local_front_with_config<F, V>(
future: F,
config: TaskConfig<V>,
) -> RawResult<LocalTaskHandle<F::Output, V>, SpawnError<F, ThreadNotifier, V, LocalOutput>>
pub fn spawn_local_front_with_config<F, V>( future: F, config: TaskConfig<V>, ) -> RawResult<LocalTaskHandle<F::Output, V>, SpawnError<F, ThreadNotifier, V, LocalOutput>>
本地队首便利派发;与spawn_local相同原值及权限,只改变下一次排队优先级。
pub fn spawn_local_front<F>(
future: F,
) -> RawResult<LocalTaskHandle<F::Output>, SpawnError<F, ThreadNotifier, (), LocalOutput>>
pub fn spawn_local_front<F>( future: F, ) -> RawResult<LocalTaskHandle<F::Output>, SpawnError<F, ThreadNotifier, (), LocalOutput>>
默认附加数据(metadata)的本地队首入口,不增加F的Send/Sync/Unpin。
Examples found in repository?
39fn roots(runtime: &ConcurrentRuntime, handle: &Handle) {
40 let value = Rc::new(7);
41 let _: Rc<usize> = runtime.block_on(Borrowed {
42 value: &value,
43 fixed: PhantomPinned,
44 });
45 let _: Rc<usize> = handle.block_on(Borrowed {
46 value: &value,
47 fixed: PhantomPinned,
48 });
49 let _ = runtime.timeout_on(
50 Borrowed {
51 value: &value,
52 fixed: PhantomPinned,
53 },
54 std::time::Duration::from_millis(1),
55 );
56 let _ = handle.spawn(SendNotSync {
57 value: Cell::new(3),
58 fixed: PhantomPinned,
59 });
60 let _ = ConcurrentRuntime::spawn_local(async { Rc::new(1usize) });
61 let _ = ConcurrentRuntime::spawn_local_front(async { Rc::new(2usize) });
62 let _ = SerialRuntime::idle_local(async { Cell::new(4usize) });
63 let _ = handle.wait_one_timeout::<Rc<usize>>(std::time::Duration::from_secs(2));
64}§impl<M, C, P, H, E, I, T> ConfiguredRuntime<M, C, P, H, E, I, T>where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
P: IdlePolicy,
H: ExecutorHooks,
impl<M, C, P, H, E, I, T> ConfiguredRuntime<M, C, P, H, E, I, T>where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
P: IdlePolicy,
H: ExecutorHooks,
§impl<M: RuntimeMode> ConfiguredRuntime<M, ManualClock, DefaultIdlePolicy, NoHooks>
impl<M: RuntimeMode> ConfiguredRuntime<M, ManualClock, DefaultIdlePolicy, NoHooks>
pub fn with_options(options: RuntimeOptions) -> Result<Self>
pub fn with_options(options: RuntimeOptions) -> Result<Self>
采用指定工作额度;不改变创建线程归属,不安装全局时钟或启动线程。
pub fn with_components<C, P, H>(
clock: C,
policy: P,
hooks: H,
options: RuntimeOptions,
) -> Result<ConfiguredRuntime<M, C, P, H>>
pub fn with_components<C, P, H>( clock: C, policy: P, hooks: H, options: RuntimeOptions, ) -> Result<ConfiguredRuntime<M, C, P, H>>
由参数推导定制类型,不把内部队列泛型传播到调用点。
Examples found in repository?
65fn declarations(clock: ManualClock) {
66 send_sync::<Handle>();
67 capabilities::<ConcurrentRuntime>();
68 capabilities::<SerialRuntime>();
69 capabilities::<Handle>();
70 let _ = ConcurrentRuntime::with_components(
71 clock,
72 LocalPolicy(Rc::new(())),
73 LocalHooks(Rc::new(())),
74 RuntimeOptions::default(),
75 );
76}pub fn with_queues<E, I, F, T>(
options: RuntimeOptions,
queues: RuntimeQueues<ManualClock, E, I, F>,
) -> Result<ConfiguredRuntime<M, ManualClock, DefaultIdlePolicy, NoHooks, E, I, T>>where
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
F: FnOnce(RuntimeId, &ManualClock, ThreadNotifier, CancelTimerOptions) -> Result<T>,
pub fn with_queues<E, I, F, T>(
options: RuntimeOptions,
queues: RuntimeQueues<ManualClock, E, I, F>,
) -> Result<ConfiguredRuntime<M, ManualClock, DefaultIdlePolicy, NoHooks, E, I, T>>where
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
F: FnOnce(RuntimeId, &ManualClock, ThreadNotifier, CancelTimerOptions) -> Result<T>,
当前线程构造,分别使用指定的队列(queue)和各缺项的默认来源。 时钟(clock)、空闲策略及钩子(hook)沿原默认,失败保留原报告(Report)。
按值接收选配。构造失败时,原线程释放已移交的队列管理者和未调用的回调(callback); 返回的报告(Report)不含这些值,也不会交出尚未完成的运行时(runtime)。
pub fn with_components_and_queues<C, P, H, E, I, F, T>(
clock: C,
policy: P,
hooks: H,
options: RuntimeOptions,
queues: RuntimeQueues<C, E, I, F>,
) -> Result<ConfiguredRuntime<M, C, P, H, E, I, T>>where
C: ExecutorClock<Instant = GlobalManualInstant>,
P: IdlePolicy,
H: ExecutorHooks,
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
F: FnOnce(RuntimeId, &C, ThreadNotifier, CancelTimerOptions) -> Result<T>,
pub fn with_components_and_queues<C, P, H, E, I, F, T>(
clock: C,
policy: P,
hooks: H,
options: RuntimeOptions,
queues: RuntimeQueues<C, E, I, F>,
) -> Result<ConfiguredRuntime<M, C, P, H, E, I, T>>where
C: ExecutorClock<Instant = GlobalManualInstant>,
P: IdlePolicy,
H: ExecutorHooks,
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
F: FnOnce(RuntimeId, &C, ThreadNotifier, CancelTimerOptions) -> Result<T>,
同时选择同源时钟(clock)、策略、钩子(hook)及具象队列(queue)。 管理者随运行时(runtime)接管,计时构造回调使用本次的线程通知句柄(ThreadNotifier)。
按值接收选配。选项校验或任一来源准备失败时,原线程释放已接管的资源和 未调用的回调(callback)。直接返回原报告(Report),调用方不会取得半成品。
§impl<M, C, P, H> ConfiguredRuntime<M, C, P, H>where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
P: IdlePolicy,
H: ExecutorHooks,
impl<M, C, P, H> ConfiguredRuntime<M, C, P, H>where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
P: IdlePolicy,
H: ExecutorHooks,
pub fn from_components(
clock: C,
policy: P,
hooks: H,
options: RuntimeOptions,
) -> Result<Self>
pub fn from_components( clock: C, policy: P, hooks: H, options: RuntimeOptions, ) -> Result<Self>
静态替换同源时钟、空闲/休眠策略及钩子;无额外Send/Sync/Default约束强加给P/H。 模式M固定普通新业务接纳;策略不能把串行改成并发。
§impl<M, C, P, H, E, I, T> ConfiguredRuntime<M, C, P, H, E, I, T>where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
P: IdlePolicy,
H: ExecutorHooks,
impl<M, C, P, H, E, I, T> ConfiguredRuntime<M, C, P, H, E, I, T>where
M: RuntimeMode,
C: ExecutorClock<Instant = GlobalManualInstant>,
E: ExternalQueueManager,
I: IdleQueueManager,
T: ExecutorTimer<Instant = GlobalManualInstant> + 'static,
P: IdlePolicy,
H: ExecutorHooks,
pub fn handle(&self) -> RuntimeHandle<C, E::Handle, I::Handle, T>
pub fn handle(&self) -> RuntimeHandle<C, E::Handle, I::Handle, T>
取得同一服务的共享访问;不移交服务推进权,也不延长本地Future的清理。