diff options
Diffstat (limited to 'monoio/src/task/mod.rs')
| -rw-r--r-- | monoio/src/task/mod.rs | 45 |
1 files changed, 41 insertions, 4 deletions
diff --git a/monoio/src/task/mod.rs b/monoio/src/task/mod.rs index 6133347..0479a3f 100644 --- a/monoio/src/task/mod.rs +++ b/monoio/src/task/mod.rs @@ -42,17 +42,17 @@ impl<S: 'static> Task<S> { fn header(&self) -> &Header { self.raw.header() } - + // 运行 (x.poll) pub(crate) fn run(self) { self.raw.poll(); } - #[cfg(feature = "sync")] + #[cfg(feature = "sync")] // 编译时带有 sync 才会编译这一段 pub(crate) unsafe fn finish(&mut self, val_slot: *mut ()) { self.raw.finish(val_slot); } } - +// 超出作用域 销毁的 特征 impl<S: 'static> Drop for Task<S> { fn drop(&mut self) { // Decrement the ref count @@ -63,8 +63,9 @@ impl<S: 'static> Drop for Task<S> { } } +// 调度器 特征 pub(crate) trait Schedule: Sized + 'static { - /// Schedule the task + /// Schedule the task | 调度任务 fn schedule(&self, task: Task<Self>); /// Schedule the task to run in the near future, yielding the thread to /// other tasks. @@ -73,6 +74,22 @@ pub(crate) trait Schedule: Sized + 'static { } } +/// 创建一个新的任务,并返回任务句柄和 JoinHandle。 +/// +/// # 参数 +/// +/// - `owner_id`:任务所有者的 ID。 +/// - `task`:要执行的任务。 +/// - `scheduler`:任务调度器。 +/// +/// # 类型参数 +/// +/// - `S`:任务调度器的类型。 +/// - `T`:要执行的任务的类型。 +/// +/// # 返回值 +/// +/// 返回一个元组,包含任务句柄和 JoinHandle。 pub(crate) fn new_task<T, S>( owner_id: usize, task: T, @@ -86,6 +103,26 @@ where unsafe { new_task_holding(owner_id, task, scheduler) } } +/// 创建一个新的任务,并返回任务句柄和 JoinHandle。 +/// +/// # 安全性 +/// +/// 这个函数是 unsafe 的,因为它使用了裸指针。 +/// +/// # 参数 +/// +/// - `owner_id`:任务所有者的 ID。 +/// - `task`:要执行的任务。 +/// - `scheduler`:任务调度器。 +/// +/// # 类型参数 +/// +/// - `S`:任务调度器的类型。 +/// - `T`:要执行的任务的类型。 +/// +/// # 返回值 +/// +/// 返回一个元组,包含任务句柄和 JoinHandle。 pub(crate) unsafe fn new_task_holding<T, S>( owner_id: usize, task: T, |
