From 87855fea8f70476adef91409220e85e97ea5c32a Mon Sep 17 00:00:00 2001 From: Folkert Date: Mon, 7 Aug 2023 14:10:46 +0200 Subject: [PATCH] use pin_project_lite instead of pin_project --- Cargo.lock | 106 ++----------------------------------- statime-linux/Cargo.toml | 4 +- statime-linux/src/main.rs | 11 ++-- statime/src/port/ticker.rs | 62 ---------------------- 4 files changed, 12 insertions(+), 171 deletions(-) delete mode 100644 statime/src/port/ticker.rs diff --git a/Cargo.lock b/Cargo.lock index 9a2282bb4..94560eb03 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -110,12 +110,6 @@ dependencies = [ "rustc-demangle", ] -[[package]] -name = "bitflags" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" - [[package]] name = "bitflags" version = "2.3.3" @@ -128,12 +122,6 @@ version = "1.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "17febce684fd15d89027105661fec94afb475cb995fbc59d2865198446ba2eea" -[[package]] -name = "bytes" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" - [[package]] name = "cc" version = "1.0.79" @@ -356,16 +344,6 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09fc20d2ca12cb9f044c93e3bd6d32d523e6e2ec3db4f7b2939cd99026ecd3f0" -[[package]] -name = "lock_api" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16" -dependencies = [ - "autocfg", - "scopeguard", -] - [[package]] name = "log" version = "0.4.19" @@ -423,54 +401,11 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core", -] - -[[package]] -name = "parking_lot_core" -version = "0.9.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447" -dependencies = [ - "cfg-if", - "libc", - "redox_syscall", - "smallvec", - "windows-targets", -] - -[[package]] -name = "pin-project" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "030ad2bc4db10a8944cb0d837f158bdfec4d4a4873ab701a95046770d11f8842" -dependencies = [ - "pin-project-internal", -] - -[[package]] -name = "pin-project-internal" -version = "1.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec2e072ecce94ec471b13398d5402c188e76ac03cf74dd1a975161b23a3f6d9c" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.23", -] - [[package]] name = "pin-project-lite" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c40d25201921e5ff0c862a505c6557ea88568a4e3ace775ab55e93f2f4f9d57" +checksum = "2c516611246607d0c04186886dbb3a754368ef82c79e9827a802c6d836dd111c" [[package]] name = "ppv-lite86" @@ -550,15 +485,6 @@ dependencies = [ "getrandom", ] -[[package]] -name = "redox_syscall" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" -dependencies = [ - "bitflags 1.3.2", -] - [[package]] name = "rustc-demangle" version = "0.1.23" @@ -571,34 +497,13 @@ version = "0.38.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "aabcb0461ebd01d6b79945797c27f8529082226cb630a9865a71870ff63532a4" dependencies = [ - "bitflags 2.3.3", + "bitflags", "errno", "libc", "linux-raw-sys", "windows-sys", ] -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - -[[package]] -name = "signal-hook-registry" -version = "1.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" -dependencies = [ - "libc", -] - -[[package]] -name = "smallvec" -version = "1.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" - [[package]] name = "socket2" version = "0.4.9" @@ -631,7 +536,7 @@ dependencies = [ "fern", "libc", "log", - "pin-project", + "pin-project-lite", "rand", "statime", "thiserror", @@ -694,13 +599,10 @@ checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" dependencies = [ "autocfg", "backtrace", - "bytes", "libc", "mio", "num_cpus", - "parking_lot", "pin-project-lite", - "signal-hook-registry", "socket2", "tokio-macros", "windows-sys", diff --git a/statime-linux/Cargo.toml b/statime-linux/Cargo.toml index cc81c82d4..3d48635f4 100644 --- a/statime-linux/Cargo.toml +++ b/statime-linux/Cargo.toml @@ -13,7 +13,7 @@ libc = { version = "0.2.147", features = ["extra_traits"] } log = "0.4.19" statime = { path = "../statime" } thiserror = "1.0.43" -pin-project = "1.1" -tokio = { version = "1.29", features = ["full"] } +pin-project-lite = "0.2.11" +tokio = { version = "1.29", features = ["net", "rt-multi-thread", "time", "macros"] } rand = { version = "0.8.5", default-features = false, features = ["std", "std_rng"] } clock-steering = { git = "https://github.com/pendulum-project/clock-steering.git", rev = "4628f18" } diff --git a/statime-linux/src/main.rs b/statime-linux/src/main.rs index c598357e0..1342434fb 100644 --- a/statime-linux/src/main.rs +++ b/statime-linux/src/main.rs @@ -135,11 +135,12 @@ fn setup_logger(level: log::LevelFilter) -> Result<(), fern::InitError> { Ok(()) } -#[pin_project::pin_project] -struct Timer { - #[pin] - timer: Sleep, - running: bool, +pin_project_lite::pin_project! { + struct Timer { + #[pin] + timer: Sleep, + running: bool, + } } impl Timer { diff --git a/statime/src/port/ticker.rs b/statime/src/port/ticker.rs deleted file mode 100644 index 186e901f3..000000000 --- a/statime/src/port/ticker.rs +++ /dev/null @@ -1,62 +0,0 @@ -use core::{ - future::Future, - pin::Pin, - task::{Context, Poll}, -}; - -use futures::Stream; -use pin_project::pin_project; - -use crate::time::Duration; - -#[pin_project] -pub struct Ticker { - #[pin] - timer: T, - reset: R, - interval: Duration, -} - -impl Ticker -where - R: FnMut(Duration) -> T, -{ - pub fn new(mut reset: R, interval: Duration) -> Self { - Self { - timer: reset(interval), - reset, - interval, - } - } - - pub fn reset(self: &mut Pin<&mut Self>) { - let interval = self.interval; - let mut this = self.as_mut().project(); - this.timer.set((this.reset)(interval)); - log::trace!("Timer reset"); - } -} - -impl Stream for Ticker -where - F: Future, - R: FnMut(Duration) -> F, -{ - type Item = F::Output; - - fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { - log::trace!("Ticker polled"); - let this = self.as_mut().project(); - match this.timer.poll(cx) { - Poll::Ready(output) => { - log::trace!("Timer expired"); - self.reset(); - Poll::Ready(Some(output)) - } - Poll::Pending => { - log::trace!("Timer pending"); - Poll::Pending - } - } - } -}