diff --git a/README-zh.md b/README-zh.md index ea46ee0a..6958f1d6 100644 --- a/README-zh.md +++ b/README-zh.md @@ -39,7 +39,7 @@ Monoio 就是这样一个 Runtime:它并不像 Tokio 那样通过公平调度 这是一个非常简单的例子,基于 Monoio 实现一个简单的 echo 服务。运行起来之后你可以通过 `nc 127.0.0.1 50002` 来连接它。 -```rust +```rust,no_run /// A echo example. /// /// Run the example and `nc 127.0.0.1 50002` in another shell. @@ -66,7 +66,7 @@ async fn main() { } } -async fn echo(stream: TcpStream) -> std::io::Result<()> { +async fn echo(mut stream: TcpStream) -> std::io::Result<()> { let mut buf: Vec = Vec::with_capacity(8 * 1024); let mut res; loop { diff --git a/README.md b/README.md index ab4aec1f..07496275 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Also, if you want to use io_uring, you must make sure your kernel supports it([5 Here is a basic example of how to use Monoio. -```rust +```rust,no_run /// A echo example. /// /// Run the example and `nc 127.0.0.1 50002` in another shell. @@ -63,7 +63,7 @@ async fn main() { } } -async fn echo(stream: TcpStream) -> std::io::Result<()> { +async fn echo(mut stream: TcpStream) -> std::io::Result<()> { let mut buf: Vec = Vec::with_capacity(8 * 1024); let mut res; loop { diff --git a/monoio/Cargo.toml b/monoio/Cargo.toml index 4b95b200..8e6f9a12 100644 --- a/monoio/Cargo.toml +++ b/monoio/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT/Apache-2.0" name = "monoio" readme = "../README.md" repository = "https://github.com/bytedance/monoio" -version = "0.1.5" +version = "0.1.6" # common dependencies [dependencies] @@ -35,7 +35,7 @@ tracing = { version = "0.1", default-features = false, features = [ ctrlc = { version = "3", optional = true } # windows dependencies(will be added when windows support finished) -[dependencies.windows-sys] +[target.'cfg(windows)'.dependencies.windows-sys] features = ["Win32_Foundation", "Win32_Networking_WinSock"] version = "0.48.0" diff --git a/monoio/src/builder.rs b/monoio/src/builder.rs index 0ca43f11..81a3f6b9 100644 --- a/monoio/src/builder.rs +++ b/monoio/src/builder.rs @@ -102,7 +102,7 @@ impl Buildable for LegacyDriver { let context = crate::runtime::Context::new(blocking_handle); #[cfg(not(feature = "sync"))] let context = crate::runtime::Context::new(); - Ok(Runtime { driver, context }) + Ok(Runtime::new(context, driver)) }) } } @@ -123,7 +123,7 @@ impl Buildable for IoUringDriver { let context = crate::runtime::Context::new(blocking_handle); #[cfg(not(feature = "sync"))] let context = crate::runtime::Context::new(); - Ok(Runtime { driver, context }) + Ok(Runtime::new(context, driver)) }) } } diff --git a/monoio/src/driver/uring/lifecycle.rs b/monoio/src/driver/uring/lifecycle.rs index c7aab154..2c1084a6 100644 --- a/monoio/src/driver/uring/lifecycle.rs +++ b/monoio/src/driver/uring/lifecycle.rs @@ -76,7 +76,8 @@ impl<'a> Ref<'a, Lifecycle> { if let Some(data) = data.take() { *ref_mut = Lifecycle::Ignored(Box::new(data)); } else { - *ref_mut = Lifecycle::Ignored(Box::new(())); // () is a ZST, so it does not allocate + *ref_mut = Lifecycle::Ignored(Box::new(())); // () is a ZST, so it does not + // allocate }; return false; } diff --git a/monoio/src/lib.rs b/monoio/src/lib.rs index fee7ca7a..1a39d536 100644 --- a/monoio/src/lib.rs +++ b/monoio/src/lib.rs @@ -6,6 +6,7 @@ #![feature(io_error_more)] #![feature(lazy_cell)] #![feature(slice_internals)] +#![feature(stmt_expr_attributes)] #[macro_use] pub mod macros; diff --git a/monoio/src/runtime.rs b/monoio/src/runtime.rs index 21000168..bffd1a70 100644 --- a/monoio/src/runtime.rs +++ b/monoio/src/runtime.rs @@ -32,6 +32,9 @@ thread_local! { scoped_thread_local!(pub(crate) static CURRENT: Context); pub(crate) struct Context { + /// Owned task set and local run queue + pub(crate) tasks: TaskQueue, + /// Thread id(not the kernel thread id but a generated unique number) pub(crate) thread_id: usize, @@ -45,8 +48,6 @@ pub(crate) struct Context { pub(crate) waker_sender_cache: std::cell::RefCell>>, - /// Owned task set and local run queue - pub(crate) tasks: TaskQueue, /// Time Handle pub(crate) time_handle: Option, @@ -95,10 +96,7 @@ impl Context { let w = v.clone(); self.unpark_cache.borrow_mut().insert(id, w); v.unpark(); - return; } - - panic!("thread to unpark has not been registered"); } #[allow(unused)] @@ -114,20 +112,21 @@ impl Context { // Write back to local cache let _ = s.send(w); self.waker_sender_cache.borrow_mut().insert(id, s); - return; } - - panic!("sender has not been registered"); } } /// Monoio runtime pub struct Runtime { - pub(crate) driver: D, pub(crate) context: Context, + pub(crate) driver: D, } impl Runtime { + pub(crate) fn new(context: Context, driver: D) -> Self { + Self { context, driver } + } + /// Block on pub fn block_on(&mut self, future: F) -> F::Output where diff --git a/monoio/src/utils/mod.rs b/monoio/src/utils/mod.rs index c4b9f8a0..6a28eae2 100644 --- a/monoio/src/utils/mod.rs +++ b/monoio/src/utils/mod.rs @@ -1,10 +1,10 @@ //! Common utils +pub(crate) mod box_into_inner; pub(crate) mod linked_list; pub(crate) mod slab; pub(crate) mod thread_id; pub(crate) mod uring_detect; -pub(crate) mod box_into_inner; mod rand; pub use rand::thread_rng_n;