diff --git a/embassy/src/channel/pubsub/mod.rs b/embassy/src/channel/pubsub/mod.rs index 11c88936..64a72a52 100644 --- a/embassy/src/channel/pubsub/mod.rs +++ b/embassy/src/channel/pubsub/mod.rs @@ -104,7 +104,7 @@ impl(&'a self) -> Result, Error> { + pub fn dyn_subscriber(&self) -> Result, Error> { self.inner.lock(|inner| { let mut s = inner.borrow_mut(); @@ -136,7 +136,7 @@ impl(&'a self) -> Result, Error> { + pub fn dyn_publisher(&self) -> Result, Error> { self.inner.lock(|inner| { let mut s = inner.borrow_mut(); @@ -369,7 +369,7 @@ impl PubSubSta } /// Error type for the [PubSubChannel] -#[derive(Debug, PartialEq, Clone)] +#[derive(Debug, PartialEq, Eq, Clone)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum Error { /// All subscriber slots are used. To add another subscriber, first another subscriber must be dropped or @@ -404,7 +404,7 @@ pub trait PubSubBehavior { } /// The result of the subscriber wait procedure -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] #[cfg_attr(feature = "defmt", derive(defmt::Format))] pub enum WaitResult { /// The subscriber did not receive all messages and lagged by the given amount of messages. diff --git a/embassy/src/executor/raw/mod.rs b/embassy/src/executor/raw/mod.rs index b8455442..7e855916 100644 --- a/embassy/src/executor/raw/mod.rs +++ b/embassy/src/executor/raw/mod.rs @@ -445,6 +445,10 @@ impl Executor { /// Wake a task by raw pointer. /// /// You can obtain task pointers from `Waker`s using [`task_from_waker`]. +/// +/// # Safety +/// +/// `task` must be a valid task pointer obtained from [`task_from_waker`]. pub unsafe fn wake_task(task: NonNull) { task.as_ref().enqueue(); } diff --git a/embassy/src/executor/spawner.rs b/embassy/src/executor/spawner.rs index 884db6b5..c8d036eb 100644 --- a/embassy/src/executor/spawner.rs +++ b/embassy/src/executor/spawner.rs @@ -93,7 +93,7 @@ impl Spawner { pub async fn for_current_executor() -> Self { poll_fn(|cx| unsafe { let task = raw::task_from_waker(cx.waker()); - let executor = (&*task.as_ptr()).executor.get(); + let executor = (*task.as_ptr()).executor.get(); Poll::Ready(Self::new(&*executor)) }) .await @@ -169,7 +169,7 @@ impl SendSpawner { pub async fn for_current_executor() -> Self { poll_fn(|cx| unsafe { let task = raw::task_from_waker(cx.waker()); - let executor = (&*task.as_ptr()).executor.get(); + let executor = (*task.as_ptr()).executor.get(); Poll::Ready(Self::new(&*executor)) }) .await diff --git a/embassy/src/util/forever.rs b/embassy/src/util/forever.rs index e367d264..0e0fee59 100644 --- a/embassy/src/util/forever.rs +++ b/embassy/src/util/forever.rs @@ -82,9 +82,17 @@ impl Forever { } } + /// Unsafely get a mutable reference to the contents of this Forever. + /// + /// # Safety + /// + /// This is undefined behavior if: + /// + /// - The `Forever` has not been initialized yet (with `put' or `put_with`), or + /// - A reference to the contents (mutable or not) already exists. #[inline(always)] #[allow(clippy::mut_from_ref)] - pub unsafe fn steal(&'static self) -> &'static mut T { + pub unsafe fn steal(&self) -> &mut T { let p = self.t.get(); let p = (&mut *p).as_mut_ptr(); &mut *p