diff --git a/actix-rt/CHANGES.md b/actix-rt/CHANGES.md index 1bd5af9d..373640d3 100644 --- a/actix-rt/CHANGES.md +++ b/actix-rt/CHANGES.md @@ -1,7 +1,7 @@ # Changes ## Unreleased - 2021-xx-xx -* Add `io-uring` feature for enabling async file Io on linux system. [#374] +* Add `io-uring` feature for enabling async file I/O on linux. [#374] * The `spawn` method can now resolve with non-unit outputs. [#369] [#369]: https://github.com/actix/actix-net/pull/369 diff --git a/actix-rt/Cargo.toml b/actix-rt/Cargo.toml index d4d169c8..b466bb76 100644 --- a/actix-rt/Cargo.toml +++ b/actix-rt/Cargo.toml @@ -29,7 +29,7 @@ actix-macros = { version = "0.2.0", optional = true } futures-core = { version = "0.3", default-features = false } tokio = { version = "1.3", features = ["rt", "net", "parking_lot", "signal", "sync", "time"] } -[target."cfg(target_os = \"linux\")".dependencies] +[target.'cfg(target_os = "linux")'.dependencies] tokio-uring = { version = "0.1", optional = true } [dev-dependencies] diff --git a/actix-rt/src/arbiter.rs b/actix-rt/src/arbiter.rs index fed7eddb..0eb06a86 100644 --- a/actix-rt/src/arbiter.rs +++ b/actix-rt/src/arbiter.rs @@ -91,11 +91,11 @@ pub struct Arbiter { } impl Arbiter { - #[cfg(any(not(target_os = "linux"), not(feature = "io-uring")))] /// Spawn a new Arbiter thread and start its event loop. /// /// # Panics /// Panics if a [System] is not registered on the current thread. + #[cfg(any(not(target_os = "linux"), not(feature = "io-uring")))] #[allow(clippy::new_without_default)] pub fn new() -> Arbiter { Self::with_tokio_rt(|| { @@ -104,10 +104,10 @@ impl Arbiter { }) } - #[cfg(any(not(target_os = "linux"), not(feature = "io-uring")))] /// Spawn a new Arbiter using the [Tokio Runtime](tokio-runtime) returned from a closure. /// /// [tokio-runtime]: tokio::runtime::Runtime + #[cfg(any(not(target_os = "linux"), not(feature = "io-uring")))] #[doc(hidden)] pub fn with_tokio_rt(runtime_factory: F) -> Arbiter where @@ -159,11 +159,11 @@ impl Arbiter { Arbiter { tx, thread_handle } } - #[cfg(all(target_os = "linux", feature = "io-uring"))] /// Spawn a new Arbiter thread and start its event loop with `tokio-uring` runtime. /// /// # Panics /// Panics if a [System] is not registered on the current thread. + #[cfg(all(target_os = "linux", feature = "io-uring"))] #[allow(clippy::new_without_default)] pub fn new() -> Arbiter { let sys = System::current(); @@ -211,7 +211,7 @@ impl Arbiter { Arbiter { tx, thread_handle } } - /// Sets up an Arbiter runner in a new System using the provided runtime local task set. + /// Sets up an Arbiter runner in a new System using the environment's local set. pub(crate) fn in_new_system() -> ArbiterHandle { let (tx, rx) = mpsc::unbounded_channel(); diff --git a/actix-rt/src/lib.rs b/actix-rt/src/lib.rs index 86bd2a8e..e078dd06 100644 --- a/actix-rt/src/lib.rs +++ b/actix-rt/src/lib.rs @@ -32,6 +32,10 @@ //! arbiter.stop(); //! arbiter.join().unwrap(); //! ``` +//! +//! # `io-uring` Support +//! There is experimental support for using io-uring with this crate by enabling the +//! `io-uring` feature. For now, it is semver exempt. #![deny(rust_2018_idioms, nonstandard_style)] #![allow(clippy::type_complexity)] diff --git a/actix-rt/src/system.rs b/actix-rt/src/system.rs index 796c7d74..4f262ede 100644 --- a/actix-rt/src/system.rs +++ b/actix-rt/src/system.rs @@ -54,7 +54,6 @@ impl System { let (sys_tx, sys_rx) = mpsc::unbounded_channel(); let rt = Runtime::from(runtime_factory()); - let sys_arbiter = rt.block_on(async { Arbiter::in_new_system() }); let system = System::construct(sys_tx, sys_arbiter.clone()); diff --git a/actix-rt/tests/tests.rs b/actix-rt/tests/tests.rs index 63fb6ddf..a49a033b 100644 --- a/actix-rt/tests/tests.rs +++ b/actix-rt/tests/tests.rs @@ -328,39 +328,30 @@ fn spawn_local() { } #[cfg(all(target_os = "linux", feature = "io-uring"))] -mod linux_only { - use std::sync::{ - atomic::{AtomicBool, Ordering}, - Arc, - }; +#[test] +fn tokio_uring_arbiter() { + let system = System::new(); + let (tx, rx) = std::sync::mpsc::channel(); - use super::*; + Arbiter::new().spawn(async move { + let handle = actix_rt::spawn(async move { + let f = tokio_uring::fs::File::create("test.txt").await.unwrap(); + let buf = b"Hello World!"; - #[test] - fn tokio_uring_arbiter() { - let system = System::new(); - let (tx, rx) = std::sync::mpsc::channel(); + let (res, _) = f.write_at(&buf[..], 0).await; + assert!(res.is_ok()); - Arbiter::new().spawn(async move { - let handle = actix_rt::spawn(async move { - let f = tokio_uring::fs::File::create("test.txt").await.unwrap(); - let buf = b"Hello World!"; + f.sync_all().await.unwrap(); + f.close().await.unwrap(); - let (res, _) = f.write_at(&buf[..], 0).await; - assert!(res.is_ok()); - - f.sync_all().await.unwrap(); - f.close().await.unwrap(); - - std::fs::remove_file("test.txt").unwrap(); - }); - - handle.await.unwrap(); - tx.send(true).unwrap(); + std::fs::remove_file("test.txt").unwrap(); }); - assert!(rx.recv().unwrap()); + handle.await.unwrap(); + tx.send(true).unwrap(); + }); - drop(system); - } + assert!(rx.recv().unwrap()); + + drop(system); } diff --git a/actix-server/CHANGES.md b/actix-server/CHANGES.md index 772982dd..08b4b553 100644 --- a/actix-server/CHANGES.md +++ b/actix-server/CHANGES.md @@ -3,7 +3,7 @@ ## Unreleased - 2021-xx-xx * Remove `config` module. `ServiceConfig`, `ServiceRuntime` public types are removed due to this change. [#349] * Remove `ServerBuilder::configure` [#349] -* Add `io-uring` feature for enabling async file Io on linux system. [#374] +* Add `io-uring` feature for enabling async file I/O on linux. [#374] [#349]: https://github.com/actix/actix-net/pull/349 [#374]: https://github.com/actix/actix-net/pull/374