diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index 920d6923..9ea008f0 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs @@ -395,9 +395,8 @@ pub struct PortInputFuture<'a> { impl<'a> Drop for PortInputFuture<'a> { fn drop(&mut self) { - unsafe { AnyPin::steal(self.pin_port) } - .conf() - .modify(|_, w| w.sense().disabled()); + let pin = unsafe { AnyPin::steal(self.pin_port) }; + pin.conf().modify(|_, w| w.sense().disabled()); } } @@ -405,18 +404,13 @@ impl<'a> Future for PortInputFuture<'a> { type Output = (); fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let dis = unsafe { AnyPin::steal(self.pin_port) } - .conf() - .read() - .sense() - .is_disabled(); - - if dis { - return Poll::Ready(()); - } - PORT_WAKERS[self.pin_port as usize].register(cx.waker()); - Poll::Pending + let pin = unsafe { AnyPin::steal(self.pin_port) }; + if pin.conf().read().sense().is_disabled() { + Poll::Ready(()) + } else { + Poll::Pending + } } } diff --git a/embassy/src/util/waker.rs b/embassy/src/util/waker.rs index cd53cca6..39315509 100644 --- a/embassy/src/util/waker.rs +++ b/embassy/src/util/waker.rs @@ -1,7 +1,7 @@ use core::ptr::{self, NonNull}; use core::task::Waker; -use atomic_polyfill::{AtomicPtr, Ordering}; +use atomic_polyfill::{compiler_fence, AtomicPtr, Ordering}; use crate::executor::raw::{task_from_waker, wake_task, TaskHeader}; @@ -63,6 +63,7 @@ impl AtomicWaker { pub fn register(&self, w: &Waker) { let w = unsafe { task_from_waker(w) }; self.waker.store(w.as_ptr(), Ordering::Relaxed); + compiler_fence(Ordering::SeqCst); } /// Wake the registered waker, if any.