From a0d17ea5ca0bd76ef4d4398c28bc8f98c4e50065 Mon Sep 17 00:00:00 2001 From: Dániel Buga Date: Mon, 16 Jun 2025 13:57:19 +0200 Subject: Remove futures-util where unnecessary --- embassy-sync/src/channel.rs | 4 ++-- embassy-sync/src/pubsub/subscriber.rs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'embassy-sync/src') diff --git a/embassy-sync/src/channel.rs b/embassy-sync/src/channel.rs index 856551417..dda91c651 100644 --- a/embassy-sync/src/channel.rs +++ b/embassy-sync/src/channel.rs @@ -443,7 +443,7 @@ where } } -impl<'ch, M, T, const N: usize> futures_util::Stream for Receiver<'ch, M, T, N> +impl<'ch, M, T, const N: usize> futures_core::Stream for Receiver<'ch, M, T, N> where M: RawMutex, { @@ -962,7 +962,7 @@ where } } -impl futures_util::Stream for Channel +impl futures_core::Stream for Channel where M: RawMutex, { diff --git a/embassy-sync/src/pubsub/subscriber.rs b/embassy-sync/src/pubsub/subscriber.rs index 6ad660cb3..649382cf1 100644 --- a/embassy-sync/src/pubsub/subscriber.rs +++ b/embassy-sync/src/pubsub/subscriber.rs @@ -115,7 +115,7 @@ impl<'a, PSB: PubSubBehavior + ?Sized, T: Clone> Unpin for Sub<'a, PSB, T> {} /// Warning: The stream implementation ignores lag results and returns all messages. /// This might miss some messages without you knowing it. -impl<'a, PSB: PubSubBehavior + ?Sized, T: Clone> futures_util::Stream for Sub<'a, PSB, T> { +impl<'a, PSB: PubSubBehavior + ?Sized, T: Clone> futures_core::Stream for Sub<'a, PSB, T> { type Item = T; fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { -- cgit From 051c63fea2fdb9cc9773c3bd311e6c423f3d1cd2 Mon Sep 17 00:00:00 2001 From: Melvin Wang Date: Wed, 18 Jun 2025 15:38:57 -0700 Subject: fix missing sync bounds --- embassy-sync/src/lazy_lock.rs | 7 ++++++- embassy-sync/src/once_lock.rs | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'embassy-sync/src') diff --git a/embassy-sync/src/lazy_lock.rs b/embassy-sync/src/lazy_lock.rs index 18e3c2019..f1bd88b61 100644 --- a/embassy-sync/src/lazy_lock.rs +++ b/embassy-sync/src/lazy_lock.rs @@ -31,7 +31,12 @@ union Data { f: ManuallyDrop, } -unsafe impl Sync for LazyLock {} +unsafe impl Sync for LazyLock +where + T: Sync, + F: Sync, +{ +} impl T> LazyLock { /// Create a new uninitialized `StaticLock`. diff --git a/embassy-sync/src/once_lock.rs b/embassy-sync/src/once_lock.rs index cd05b986d..1e848685a 100644 --- a/embassy-sync/src/once_lock.rs +++ b/embassy-sync/src/once_lock.rs @@ -42,7 +42,7 @@ pub struct OnceLock { data: Cell>, } -unsafe impl Sync for OnceLock {} +unsafe impl Sync for OnceLock where T: Sync {} impl OnceLock { /// Create a new uninitialized `OnceLock`. -- cgit From 72248a601a9ea28ac696f186e2cbe4c2f128a133 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sun, 29 Jun 2025 22:37:11 +0200 Subject: Update Rust nightly, stable. --- embassy-sync/src/pubsub/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'embassy-sync/src') diff --git a/embassy-sync/src/pubsub/mod.rs b/embassy-sync/src/pubsub/mod.rs index 606efff0a..9206b9383 100644 --- a/embassy-sync/src/pubsub/mod.rs +++ b/embassy-sync/src/pubsub/mod.rs @@ -88,7 +88,7 @@ impl Result, Error> { + pub fn subscriber(&self) -> Result, Error> { self.inner.lock(|inner| { let mut s = inner.borrow_mut(); @@ -120,7 +120,7 @@ impl Result, Error> { + pub fn publisher(&self) -> Result, Error> { self.inner.lock(|inner| { let mut s = inner.borrow_mut(); @@ -151,13 +151,13 @@ impl ImmediatePublisher { + pub fn immediate_publisher(&self) -> ImmediatePublisher<'_, M, T, CAP, SUBS, PUBS> { ImmediatePublisher(ImmediatePub::new(self)) } /// Create a new publisher that can only send immediate messages. /// This kind of publisher does not take up a publisher slot. - pub fn dyn_immediate_publisher(&self) -> DynImmediatePublisher { + pub fn dyn_immediate_publisher(&self) -> DynImmediatePublisher<'_, T> { DynImmediatePublisher(ImmediatePub::new(self)) } -- cgit From e4aa539708781af2474240c5c16456ffe554754b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 9 Jul 2025 14:02:20 +0200 Subject: add embassy sync channel example for message passing between interrupt and task --- embassy-sync/src/channel.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'embassy-sync/src') diff --git a/embassy-sync/src/channel.rs b/embassy-sync/src/channel.rs index dda91c651..a0e39fcb5 100644 --- a/embassy-sync/src/channel.rs +++ b/embassy-sync/src/channel.rs @@ -17,6 +17,31 @@ //! messages that it can store, and if this limit is reached, trying to send //! another message will result in an error being returned. //! +//! # Example: Message passing between task and interrupt handler +//! +//! ```rust +//! use embassy_sync::channel::Channel; +//! use embassy_sync::blocking_mutex::raw::CriticalSectionRawMutex; +//! +//! static SHARED_CHANNEL: Channel = Channel::new(); +//! +//! fn my_interrupt_handler() { +//! // Do some work.. +//! // ... +//! if let Err(e) = SHARED_CHANNEL.sender().try_send(42) { +//! // Channel is full.. +//! } +//! } +//! +//! async fn my_async_task() { +//! // ... +//! let receiver = SHARED_CHANNEL.receiver(); +//! loop { +//! let data_from_interrupt = receiver.receive().await; +//! // Do something with the data. +//! } +//! } +//! ``` use core::cell::RefCell; use core::future::Future; -- cgit From 42c8379c5a571aa76214cdd73ef05a2c720eeb6e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 9 Jul 2025 14:21:19 +0200 Subject: some minor documentation fixes --- embassy-sync/src/mutex.rs | 2 +- embassy-sync/src/pipe.rs | 8 ++++---- embassy-sync/src/priority_channel.rs | 4 ++-- embassy-sync/src/pubsub/publisher.rs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) (limited to 'embassy-sync/src') diff --git a/embassy-sync/src/mutex.rs b/embassy-sync/src/mutex.rs index 7528a9f68..67c682704 100644 --- a/embassy-sync/src/mutex.rs +++ b/embassy-sync/src/mutex.rs @@ -23,7 +23,7 @@ struct State { /// Async mutex. /// -/// The mutex is generic over a blocking [`RawMutex`](crate::blocking_mutex::raw::RawMutex). +/// The mutex is generic over a blocking [RawMutex]. /// The raw mutex is used to guard access to the internal "is locked" flag. It /// is held for very short periods only, while locking and unlocking. It is *not* held /// for the entire time the async Mutex is locked. diff --git a/embassy-sync/src/pipe.rs b/embassy-sync/src/pipe.rs index 2598652d2..df3b28b45 100644 --- a/embassy-sync/src/pipe.rs +++ b/embassy-sync/src/pipe.rs @@ -152,7 +152,7 @@ where impl<'p, M, const N: usize> Unpin for ReadFuture<'p, M, N> where M: RawMutex {} -/// Future returned by [`Pipe::fill_buf`] and [`Reader::fill_buf`]. +/// Future returned by [`Reader::fill_buf`]. #[must_use = "futures do nothing unless you `.await` or poll them"] pub struct FillBufFuture<'p, M, const N: usize> where @@ -587,7 +587,7 @@ where } } -/// Write-only access to a [`DynamicPipe`]. +/// Write-only access to the dynamic pipe. pub struct DynamicWriter<'p> { pipe: &'p dyn DynamicPipe, } @@ -657,7 +657,7 @@ where } } -/// Read-only access to a [`DynamicPipe`]. +/// Read-only access to a dynamic pipe. pub struct DynamicReader<'p> { pipe: &'p dyn DynamicPipe, } @@ -742,7 +742,7 @@ where } } -/// Future returned by [`DynamicPipe::fill_buf`] and [`DynamicReader::fill_buf`]. +/// Future returned by [`DynamicReader::fill_buf`]. #[must_use = "futures do nothing unless you `.await` or poll them"] pub struct DynamicFillBufFuture<'p> { pipe: Option<&'p dyn DynamicPipe>, diff --git a/embassy-sync/src/priority_channel.rs b/embassy-sync/src/priority_channel.rs index 623c52993..a6fbe8def 100644 --- a/embassy-sync/src/priority_channel.rs +++ b/embassy-sync/src/priority_channel.rs @@ -1,7 +1,7 @@ //! A queue for sending values between asynchronous tasks. //! //! Similar to a [`Channel`](crate::channel::Channel), however [`PriorityChannel`] sifts higher priority items to the front of the queue. -//! Priority is determined by the `Ord` trait. Priority behavior is determined by the [`Kind`](heapless::binary_heap::Kind) parameter of the channel. +//! Priority is determined by the `Ord` trait. Priority behavior is determined by the [Kind] parameter of the channel. use core::cell::RefCell; use core::future::Future; @@ -473,7 +473,7 @@ where /// received from the channel. /// /// Sent data may be reordered based on their priority within the channel. -/// For example, in a [`Max`](heapless::binary_heap::Max) [`PriorityChannel`] +/// For example, in a [Max][PriorityChannel] /// containing `u32`'s, data sent in the following order `[1, 2, 3]` will be received as `[3, 2, 1]`. pub struct PriorityChannel where diff --git a/embassy-sync/src/pubsub/publisher.rs b/embassy-sync/src/pubsub/publisher.rs index 7a1ab66de..2af1a9334 100644 --- a/embassy-sync/src/pubsub/publisher.rs +++ b/embassy-sync/src/pubsub/publisher.rs @@ -75,7 +75,7 @@ impl<'a, PSB: PubSubBehavior + ?Sized, T: Clone> Pub<'a, PSB, T> { self.channel.is_full() } - /// Create a [`futures::Sink`] adapter for this publisher. + /// Create a [futures_sink::Sink] adapter for this publisher. #[inline] pub const fn sink(&self) -> PubSink<'a, '_, PSB, T> { PubSink { publ: self, fut: None } -- cgit From da392ed942bbf78117f1dbba32208458de7cdea8 Mon Sep 17 00:00:00 2001 From: Robin Mueller <31589589+robamu@users.noreply.github.com> Date: Wed, 9 Jul 2025 14:26:20 +0200 Subject: Update embassy-sync/src/mutex.rs Co-authored-by: James Munns --- embassy-sync/src/mutex.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'embassy-sync/src') diff --git a/embassy-sync/src/mutex.rs b/embassy-sync/src/mutex.rs index 67c682704..8496f34bf 100644 --- a/embassy-sync/src/mutex.rs +++ b/embassy-sync/src/mutex.rs @@ -23,7 +23,7 @@ struct State { /// Async mutex. /// -/// The mutex is generic over a blocking [RawMutex]. +/// The mutex is generic over a blocking [`RawMutex`]. /// The raw mutex is used to guard access to the internal "is locked" flag. It /// is held for very short periods only, while locking and unlocking. It is *not* held /// for the entire time the async Mutex is locked. -- cgit From 9892963da946aa896d9387916ee2b5d509b63e3b Mon Sep 17 00:00:00 2001 From: Robin Mueller <31589589+robamu@users.noreply.github.com> Date: Wed, 9 Jul 2025 14:28:18 +0200 Subject: Update embassy-sync/src/priority_channel.rs Co-authored-by: James Munns --- embassy-sync/src/priority_channel.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'embassy-sync/src') diff --git a/embassy-sync/src/priority_channel.rs b/embassy-sync/src/priority_channel.rs index a6fbe8def..6765a1503 100644 --- a/embassy-sync/src/priority_channel.rs +++ b/embassy-sync/src/priority_channel.rs @@ -1,7 +1,7 @@ //! A queue for sending values between asynchronous tasks. //! //! Similar to a [`Channel`](crate::channel::Channel), however [`PriorityChannel`] sifts higher priority items to the front of the queue. -//! Priority is determined by the `Ord` trait. Priority behavior is determined by the [Kind] parameter of the channel. +//! Priority is determined by the `Ord` trait. Priority behavior is determined by the [`Kind`] parameter of the channel. use core::cell::RefCell; use core::future::Future; -- cgit From 554fbef571cf9f4692d6361d66f962df926615df Mon Sep 17 00:00:00 2001 From: Robin Mueller <31589589+robamu@users.noreply.github.com> Date: Wed, 9 Jul 2025 14:31:04 +0200 Subject: Update embassy-sync/src/priority_channel.rs Co-authored-by: James Munns --- embassy-sync/src/priority_channel.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'embassy-sync/src') diff --git a/embassy-sync/src/priority_channel.rs b/embassy-sync/src/priority_channel.rs index 6765a1503..715a20e86 100644 --- a/embassy-sync/src/priority_channel.rs +++ b/embassy-sync/src/priority_channel.rs @@ -473,7 +473,7 @@ where /// received from the channel. /// /// Sent data may be reordered based on their priority within the channel. -/// For example, in a [Max][PriorityChannel] +/// For example, in a [`Max`] [`PriorityChannel`] /// containing `u32`'s, data sent in the following order `[1, 2, 3]` will be received as `[3, 2, 1]`. pub struct PriorityChannel where -- cgit From fa0f6bc670c29b799e0ef8812de041727c5d86f3 Mon Sep 17 00:00:00 2001 From: Robin Mueller <31589589+robamu@users.noreply.github.com> Date: Wed, 9 Jul 2025 14:31:42 +0200 Subject: Update embassy-sync/src/pubsub/publisher.rs Co-authored-by: James Munns --- embassy-sync/src/pubsub/publisher.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'embassy-sync/src') diff --git a/embassy-sync/src/pubsub/publisher.rs b/embassy-sync/src/pubsub/publisher.rs index 2af1a9334..52a52f926 100644 --- a/embassy-sync/src/pubsub/publisher.rs +++ b/embassy-sync/src/pubsub/publisher.rs @@ -75,7 +75,7 @@ impl<'a, PSB: PubSubBehavior + ?Sized, T: Clone> Pub<'a, PSB, T> { self.channel.is_full() } - /// Create a [futures_sink::Sink] adapter for this publisher. + /// Create a [`futures_sink::Sink`] adapter for this publisher. #[inline] pub const fn sink(&self) -> PubSink<'a, '_, PSB, T> { PubSink { publ: self, fut: None } -- cgit