From 0e4c56d8ebac42b1fe1f270bf2fe47331ce56e95 Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Sun, 12 Nov 2023 14:48:18 +0000 Subject: [PATCH] Restore Ping trait constraints; relax Subscription: Send in AsyncSubscription --- CHANGELOG.md | 3 +++ Cargo.toml | 2 +- src/ping.rs | 8 ++++---- src/utils/asyncify/event_bus.rs | 34 ++++++++++++++++----------------- 4 files changed, 25 insertions(+), 22 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2f88464..ec13da1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.26.3] - 2023-11-12 +* Traits `EventBus` and `TimerService`: do not allow subscriptions with non-static callbacks, as these are impossible to implement safely on ESP IDF + ## [0.26.2] - 2023-11-05 * A temporary workaround for https://github.com/rust-lang/rust/issues/117602 diff --git a/Cargo.toml b/Cargo.toml index 6079e90..834727c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "embedded-svc" -version = "0.26.2" +version = "0.26.3" authors = ["Ivan Markov "] edition = "2018" resolver = "2" diff --git a/src/ping.rs b/src/ping.rs index a880c0b..0caad5c 100644 --- a/src/ping.rs +++ b/src/ping.rs @@ -63,7 +63,7 @@ pub trait Ping { fn ping(&mut self, ip: ipv4::Ipv4Addr, conf: &Configuration) -> Result; - fn ping_details( + fn ping_details( &mut self, ip: ipv4::Ipv4Addr, conf: &Configuration, @@ -81,7 +81,7 @@ where (*self).ping(ip, conf) } - fn ping_details( + fn ping_details( &mut self, ip: ipv4::Ipv4Addr, conf: &Configuration, @@ -107,7 +107,7 @@ pub mod asynch { conf: &Configuration, ) -> Result; - async fn ping_details( + async fn ping_details( &mut self, ip: ipv4::Ipv4Addr, conf: &Configuration, @@ -129,7 +129,7 @@ pub mod asynch { (*self).ping(ip, conf).await } - async fn ping_details( + async fn ping_details( &mut self, ip: ipv4::Ipv4Addr, conf: &Configuration, diff --git a/src/utils/asyncify/event_bus.rs b/src/utils/asyncify/event_bus.rs index 542de7e..83a7611 100644 --- a/src/utils/asyncify/event_bus.rs +++ b/src/utils/asyncify/event_bus.rs @@ -83,21 +83,21 @@ where } } -pub struct SubscriptionState { - subscription: Option, +pub struct SubscriptionState

{ value: Option

, waker: Option, } #[allow(clippy::type_complexity)] -pub struct AsyncSubscription( - Arc<(Mutex>, Condvar)>, - PhantomData E>, -) +pub struct AsyncSubscription where CV: RawCondvar, P: Send, - S: Send; +{ + state: Arc<(Mutex>, Condvar)>, + _subscription: S, + _pd: PhantomData E>, +} impl AsyncSubscription where @@ -126,7 +126,7 @@ where S: Send, { fn drop(&mut self) { - let mut state = self.0 .0 .0.lock(); + let mut state = self.0.state.0.lock(); state.waker = None; } } @@ -141,18 +141,18 @@ where type Output = Result; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let mut state = self.0 .0 .0.lock(); + let mut state = self.0.state.0.lock(); let value = state.value.take(); if let Some(value) = value { - self.0 .0 .1.notify_all(); + self.0.state.1.notify_all(); Poll::Ready(Ok(value)) } else { state.waker = Some(cx.waker().clone()); - self.0 .0 .1.notify_all(); + self.0.state.1.notify_all(); Poll::Pending } @@ -187,11 +187,9 @@ where where P: Clone + Send + 'static, E: crate::event_bus::EventBus

, - for<'a> E::Subscription<'a>: Send + 'static, { let state = Arc::new(( Mutex::new(SubscriptionState { - subscription: None, value: None, waker: None, }), @@ -222,9 +220,11 @@ where } })?; - state.0.lock().subscription = Some(subscription); - - Ok(AsyncSubscription(state, PhantomData)) + Ok(AsyncSubscription { + state, + _subscription: subscription, + _pd: PhantomData, + }) } } @@ -367,7 +367,7 @@ mod async_traits_impl { CV::RawMutex: Send + Sync + 'static, P: Clone + Send + 'static, E: crate::event_bus::EventBus

, - for<'a> E::Subscription<'a>: Send + 'static, + for<'a> E::Subscription<'a>: Send, { type Subscription<'a> = AsyncSubscription, E::Error> where Self: 'a;