diff options
| author | zy <[email protected]> | 2023-09-01 10:43:54 +0000 |
|---|---|---|
| committer | zy <[email protected]> | 2023-09-01 10:43:54 +0000 |
| commit | a038a38a1f52d14a2af6f99c98c9a6cbc367d39e (patch) | |
| tree | 38ddb48644310e12a3f918e5966ca73d7d257168 | |
| parent | 4ecbf24689b0a0f214a972983a33b41064c5ea81 (diff) | |
6/51
| -rw-r--r-- | monoio/src/driver/legacy/mod.rs | 8 | ||||
| -rw-r--r-- | monoio/src/driver/legacy/scheduled_io.rs | 3 | ||||
| -rw-r--r-- | monoio/src/driver/mod.rs | 3 | ||||
| -rw-r--r-- | monoio/src/driver/op.rs | 18 |
4 files changed, 18 insertions, 14 deletions
diff --git a/monoio/src/driver/legacy/mod.rs b/monoio/src/driver/legacy/mod.rs index a92a702..483cd70 100644 --- a/monoio/src/driver/legacy/mod.rs +++ b/monoio/src/driver/legacy/mod.rs @@ -26,7 +26,7 @@ mod waker; pub(crate) use waker::UnparkHandle; pub(crate) struct LegacyInner { - pub(crate) io_dispatch: Slab<ScheduledIo>, + pub(crate) io_dispatch: Slab<ScheduledIo>, // #[cfg(unix)] events: Option<mio::Events>, #[cfg(unix)] @@ -260,7 +260,7 @@ impl LegacyInner { pub(crate) fn poll_op<T: OpAble>( this: &Rc<UnsafeCell<Self>>, - data: &mut T, + data: &mut T, // 实际上是个 OpAble cx: &mut Context<'_>, ) -> Poll<CompletionMeta> { let inner = unsafe { &mut *this.get() }; @@ -269,6 +269,7 @@ impl LegacyInner { None => { // if there is no index provided, it means the action does not rely on fd // readiness. do syscall right now. + // 如果没有提供索引,则表示该操作不依赖于 fd 的准备就绪.立即执行系统调用. return Poll::Ready(CompletionMeta { result: OpAble::legacy_call(data), flags: 0, @@ -277,14 +278,17 @@ impl LegacyInner { }; // wait io ready and do syscall + // 等待 io 准备就绪并执行系统调用 let mut scheduled_io = inner.io_dispatch.get(index).expect("scheduled_io lost"); let ref_mut = scheduled_io.as_mut(); loop { let readiness = ready!(ref_mut.poll_readiness(cx, direction)); // check if canceled + // 检查是否已取消 if readiness.is_canceled() { // clear CANCELED part only + // 只清除 CANCELED 部分 ref_mut.clear_readiness(readiness & Ready::CANCELED); return Poll::Ready(CompletionMeta { result: Err(io::Error::from_raw_os_error(125)), diff --git a/monoio/src/driver/legacy/scheduled_io.rs b/monoio/src/driver/legacy/scheduled_io.rs index 7b3b713..41d901f 100644 --- a/monoio/src/driver/legacy/scheduled_io.rs +++ b/monoio/src/driver/legacy/scheduled_io.rs @@ -2,8 +2,9 @@ use std::task::{Context, Poll, Waker}; use super::ready::{Direction, Ready}; +// IO 上等待的 waker pub(crate) struct ScheduledIo { - readiness: Ready, + readiness: Ready, // IO 的状态 /// Waker used for AsyncRead. reader: Option<Waker>, diff --git a/monoio/src/driver/mod.rs b/monoio/src/driver/mod.rs index af2f2ce..0ad9998 100644 --- a/monoio/src/driver/mod.rs +++ b/monoio/src/driver/mod.rs @@ -123,8 +123,7 @@ impl Inner { } #[allow(unused)] - // 执行 poll 返回状态(Poll:Pending or Poll:Ready<>) - // 根据 io 状态选择,返回不同的状态 + // poll op fn poll_op<T: OpAble>( &self, data: &mut T, diff --git a/monoio/src/driver/op.rs b/monoio/src/driver/op.rs index 1bfa246..979f35a 100644 --- a/monoio/src/driver/op.rs +++ b/monoio/src/driver/op.rs @@ -39,15 +39,15 @@ pub(crate) struct Op<T: 'static> { /// 返回存储的状态与操作的结果。 #[derive(Debug)] pub(crate) struct Completion<T> { - pub(crate) data: T, - pub(crate) meta: CompletionMeta, + pub(crate) data: T, // 返回的数据 + pub(crate) meta: CompletionMeta, // 操作状态? } /// Operation completion meta info. /// 操作完成元信息。 #[derive(Debug)] pub(crate) struct CompletionMeta { - pub(crate) result: io::Result<u32>, // Result of the operation + pub(crate) result: io::Result<u32>, // Result of the operation | 操作执行的结果 #[allow(unused)] pub(crate) flags: u32, } @@ -125,7 +125,7 @@ impl<T> Op<T> { T: OpAble, { #[cfg(feature = "legacy")] // 兼容模式 - // 如果是兼容模式 + // 如果是兼容模式 if is_legacy() { return if let Some((dir, id)) = self.data.as_ref().unwrap().legacy_interest() { OpCanceller { @@ -151,12 +151,12 @@ impl<T> Future for Op<T> where T: Unpin + OpAble + 'static, // T 要实现 OpAble { - type Output = Completion<T>; + type Output = Completion<T>; // future 的返回类型要是 Completion<T> fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> { - let me = &mut *self; - let data_mut = me.data.as_mut().expect("unexpected operation state"); - // 调用 driver 执行 io + let me = &mut *self; // 自身可变引用 + let data_mut = me.data.as_mut().expect("unexpected operation state"); // T 的可变引用(限制是 OpAble 的实现) + // 调用 driver 执行 io, 推动 future 到 ready 状态 let meta = ready!(me.driver.poll_op::<T>(data_mut, me.index, cx)); me.index = usize::MAX; @@ -177,7 +177,7 @@ pub(crate) fn is_legacy() -> bool { true } -#[cfg(target_os = "linux")] +#[cfg(target_os = "linux")] // 是否是兼容模式 pub(crate) fn is_legacy() -> bool { super::CURRENT.with(|inner| inner.is_legacy()) |
