From 2583fd74d1639073d3ee1b3dcb8c295cfd840a13 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Thu, 13 Apr 2023 12:21:34 +0200 Subject: [PATCH 1/3] chore: update dependencies --- Cargo.lock | 153 +++++++++++++++++++++++++++++++++++++---------------- Cargo.toml | 12 ++--- 2 files changed, 112 insertions(+), 53 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b70293b..a3f069b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "amplify" -version = "4.0.0-beta.17" +version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72eaf6c304959bf74ba94973ebea642729f583000ef77e7139844642cc066004" +checksum = "f26966af46e0d200e8bf2b7f16230997c1c3f2d141bc27ccc091c012ed527b58" dependencies = [ "amplify_derive", "amplify_num", @@ -16,9 +16,9 @@ dependencies = [ [[package]] name = "amplify_derive" -version = "4.0.0-alpha.6" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01c4835e964725149d7961ec5af2ca1302f6f68c8c738b4acb06185f596c3333" +checksum = "580f12b79a9e10cfa8d2515128d83a53f387e290096a75904c92b8a2a4d542a6" dependencies = [ "amplify_syn", "proc-macro2", @@ -34,9 +34,9 @@ checksum = "ddce3bc63e807ea02065e8d8b702695f3d302ae4158baddff8b0ce5c73947251" [[package]] name = "amplify_syn" -version = "2.0.0-beta.2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e3db5cb96f8f18a9566a975c521b77485f6f8e3e8d866d0f52369446ba31274" +checksum = "29b08d74fda406d5a94abfdcdb91ba13bb06562ccf0a4581867fa924ca242b01" dependencies = [ "proc-macro2", "quote", @@ -56,16 +56,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" [[package]] -name = "bumpalo" -version = "3.12.0" +name = "bitflags" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] -name = "cc" -version = "1.0.79" +name = "bumpalo" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" [[package]] name = "cfg-if" @@ -73,11 +73,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "concurrent-queue" +version = "2.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62ec6771ecfa0762d24683ee5a32ad78487a3d3afdc0fb8cae19d2c5deb50b7c" +dependencies = [ + "crossbeam-utils", +] + [[package]] name = "crossbeam-channel" -version = "0.5.6" +version = "0.5.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" +checksum = "a33c2bf77f2df06183c3aa30d1e96c0695a313d4f9c453cc3762a6db39f99200" dependencies = [ "cfg-if", "crossbeam-utils", @@ -104,7 +113,7 @@ dependencies = [ [[package]] name = "io-reactor" -version = "0.1.1" +version = "0.2.0" dependencies = [ "amplify", "crossbeam-channel", @@ -149,25 +158,33 @@ version = "1.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +[[package]] +name = "pin-project-lite" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" + [[package]] name = "polling" -version = "2.5.2" +version = "2.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22122d5ec4f9fe1b3916419b76be1e80bcb93f618d071d2edf841b137b2a2bd6" +checksum = "4be1c66a6add46bff50935c313dae30a5030cf8385c5206e8a95e9e9def974aa" dependencies = [ "autocfg", + "bitflags", "cfg-if", + "concurrent-queue", "libc", "log", - "wepoll-ffi", - "windows-sys 0.42.0", + "pin-project-lite", + "windows-sys 0.48.0", ] [[package]] name = "popol" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "839bf4ab18d0c74859e01a22365a5c573e7b3f0ff36a11c4250f1e5bd220f397" +checksum = "a953dd115cbe3b9d10340d47e6825a9700059a2fee12cee722975776caf3c531" dependencies = [ "libc", ] @@ -284,51 +301,51 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" [[package]] -name = "wepoll-ffi" -version = "0.1.2" +name = "windows-sys" +version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d743fdedc5c64377b5fc2bc036b01c7fd642205a0d96356034ae3404d49eb7fb" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "cc", + "windows-targets 0.42.1", ] [[package]] name = "windows-sys" -version = "0.42.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows-targets 0.48.0", ] [[package]] -name = "windows-sys" -version = "0.45.0" +name = "windows-targets" +version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" dependencies = [ - "windows-targets", + "windows_aarch64_gnullvm 0.42.1", + "windows_aarch64_msvc 0.42.1", + "windows_i686_gnu 0.42.1", + "windows_i686_msvc 0.42.1", + "windows_x86_64_gnu 0.42.1", + "windows_x86_64_gnullvm 0.42.1", + "windows_x86_64_msvc 0.42.1", ] [[package]] name = "windows-targets" -version = "0.42.1" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e2522491fbfcd58cc84d47aeb2958948c4b8982e9a2d8a2a35bbaed431390e7" +checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] @@ -337,38 +354,80 @@ version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8c9864e83243fdec7fc9c5444389dcbbfd258f745e7853198f365e3c4968a608" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + [[package]] name = "windows_aarch64_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4c8b1b673ffc16c47a9ff48570a9d85e25d265735c503681332589af6253c6c7" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + [[package]] name = "windows_i686_gnu" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "de3887528ad530ba7bdbb1faa8275ec7a1155a45ffa57c37993960277145d640" +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + [[package]] name = "windows_i686_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf4d1122317eddd6ff351aa852118a2418ad4214e6613a50e0191f7004372605" +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + [[package]] name = "windows_x86_64_gnu" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c1040f221285e17ebccbc2591ffdc2d44ee1f9186324dd3e84e99ac68d699c45" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "628bfdf232daa22b0d64fdb62b09fcc36bb01f05a3939e20ab73aaf9470d0463" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + [[package]] name = "windows_x86_64_msvc" version = "0.42.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "447660ad36a13288b1db4d4248e857b510e8c3a225c822ba4fb748c0aafecffd" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" diff --git a/Cargo.toml b/Cargo.toml index 102e31a..416ddaf 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "io-reactor" -version = "0.1.1" +version = "0.2.0" description = "Concurrent I/O resource management using reactor pattern" authors = [ "Dr. Maxim Orlovsky ", @@ -19,12 +19,12 @@ readme = "README.md" name = "reactor" [dependencies] -amplify = { version = "4.0.0-beta.17", features = ["hex"] } -crossbeam-channel = "0.5.6" -popol = { version = "2.1.0", optional = true } -polling = { version = "2.4.0", optional = true } +amplify = { version = "4.0.0", features = ["hex"] } +crossbeam-channel = "0.5.8" +popol = { version = "2.2.0", optional = true } +polling = { version = "2.7.0", optional = true } # epoll = { version = "4.3.1", optional = true } - NB: epoll not supported on MacOS -mio = { version = "0.8.5", optional = true } +mio = { version = "0.8.6", optional = true } log = { version = "0.4.17", optional = true, features = ["kv_unstable"] } libc = "0.2.139" From e03dd913549425e6f771148fe139bed161229d41 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Fri, 14 Apr 2023 11:11:16 +0200 Subject: [PATCH 2/3] waker: refactor to avoid recursion --- src/reactor.rs | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/reactor.rs b/src/reactor.rs index 693541b..f38574e 100644 --- a/src/reactor.rs +++ b/src/reactor.rs @@ -400,32 +400,34 @@ impl Controller { #[cfg(feature = "log")] log::trace!(target: "reactor-controller", "Wakening the reactor"); - #[allow(unused_variables)] - let mut waker = self.waker.lock().map_err(|err| { - #[cfg(feature = "log")] - log::error!(target: "reactor-controller", "Waker lock is poisoned: {err}"); - WouldBlock - })?; - match waker.write_all(&[0x1]) { - Ok(_) => Ok(()), - Err(e) if e.kind() == WouldBlock => { - #[cfg(feature = "log")] - log::error!(target: "reactor-controller", "Waker write queue got overfilled, resetting and repeating..."); - - reset_fd(&waker.as_raw_fd())?; - self.wake() + let mut waker = loop { + match self.waker.lock() { + Err(err) => { + #[cfg(feature = "log")] + log::error!(target: "reactor-controller", "Waker lock is poisoned: {err}"); + } + Ok(waker) => break waker, } - Err(e) if e.kind() == Interrupted => { - #[cfg(feature = "log")] - log::error!(target: "reactor-controller", "Waker failure, repeating..."); + }; - self.wake() - } - Err(e) => { - #[cfg(feature = "log")] - log::error!(target: "reactor-controller", "Waker error: {e}"); + loop { + match waker.write_all(&[0x1]) { + Ok(_) => return Ok(()), + Err(e) if e.kind() == WouldBlock => { + #[cfg(feature = "log")] + log::error!(target: "reactor-controller", "Waker write queue got overfilled, resetting and repeating..."); + reset_fd(&waker.as_raw_fd())?; + } + Err(e) if e.kind() == Interrupted => { + #[cfg(feature = "log")] + log::error!(target: "reactor-controller", "Waker failure, repeating..."); + } + Err(e) => { + #[cfg(feature = "log")] + log::error!(target: "reactor-controller", "Waker error: {e}"); - Err(e) + return Err(e); + } } } } From 5a331ea90f902c3b8013bf3510af0fa44d9b45a7 Mon Sep 17 00:00:00 2001 From: Dr Maxim Orlovsky Date: Fri, 14 Apr 2023 11:19:32 +0200 Subject: [PATCH 3/3] waker: remove Mutex --- src/reactor.rs | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/src/reactor.rs b/src/reactor.rs index f38574e..624d373 100644 --- a/src/reactor.rs +++ b/src/reactor.rs @@ -26,7 +26,7 @@ use std::fmt::{Debug, Display, Formatter}; use std::io::Write; use std::os::unix::io::{AsRawFd, RawFd}; use std::os::unix::net::UnixStream; -use std::sync::{Arc, Mutex}; +use std::sync::Arc; use std::thread::JoinHandle; use std::time::Duration; use std::{io, thread}; @@ -284,7 +284,7 @@ impl Reactor { let controller = Controller { ctl_send, - waker: Arc::new(Mutex::new(waker_writer)), + waker: Arc::new(waker_writer), }; #[cfg(feature = "log")] @@ -343,7 +343,7 @@ enum Ctl { /// [`Handler::Command`] for the details). pub struct Controller { ctl_send: chan::Sender>, - waker: Arc>, + waker: Arc, } impl Clone for Controller { @@ -400,23 +400,14 @@ impl Controller { #[cfg(feature = "log")] log::trace!(target: "reactor-controller", "Wakening the reactor"); - let mut waker = loop { - match self.waker.lock() { - Err(err) => { - #[cfg(feature = "log")] - log::error!(target: "reactor-controller", "Waker lock is poisoned: {err}"); - } - Ok(waker) => break waker, - } - }; - loop { - match waker.write_all(&[0x1]) { + let mut waker = self.waker.as_ref(); + match (&mut waker).write_all(&[0x1]) { Ok(_) => return Ok(()), Err(e) if e.kind() == WouldBlock => { #[cfg(feature = "log")] log::error!(target: "reactor-controller", "Waker write queue got overfilled, resetting and repeating..."); - reset_fd(&waker.as_raw_fd())?; + reset_fd(&self.waker.as_raw_fd())?; } Err(e) if e.kind() == Interrupted => { #[cfg(feature = "log")] @@ -489,7 +480,7 @@ impl Runtime { let controller = Controller { ctl_send, - waker: Arc::new(Mutex::new(waker_writer)), + waker: Arc::new(waker_writer), }; Ok(Runtime {