From 46a3a9a58abeaf53cd78aa081059470d66cd2715 Mon Sep 17 00:00:00 2001 From: Matt Johnston Date: Sun, 16 Jun 2024 22:30:48 +0800 Subject: [PATCH] embassy: Change polonius workaround to make the future Send Previously the *mut was held across .await points, so the future wasn't Send which meant it only worked with single-threaded executors. --- embassy/src/embassy_sunset.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/embassy/src/embassy_sunset.rs b/embassy/src/embassy_sunset.rs index 6faf313..f63cc31 100644 --- a/embassy/src/embassy_sunset.rs +++ b/embassy/src/embassy_sunset.rs @@ -295,15 +295,12 @@ impl<'a> EmbassySunset<'a> { pub(crate) async fn progress<'g, 'f>(&'g self, ph: &'f mut ProgressHolder<'g, 'a>) -> Result> { + ph.g = None; + #[cfg(feature = "try-polonius")] let guard = &mut ph.g; - *guard = None; - - #[cfg(not(feature = "try-polonius"))] - let guardptr = guard as *mut Option<_>; // poll progress until we get an actual event to return loop { - debug_assert!(guard.is_none()); // Safety: At the start of the loop iteration nothing is borrowing from // guard, it is set to None. We dereference through a pointer to lose the 'f @@ -313,7 +310,8 @@ impl<'a> EmbassySunset<'a> { // Once polonius is implemented this is unnecessary. polonius-the-crab // can't be used since it would require an async closure. #[cfg(not(feature = "try-polonius"))] - let guard = unsafe { &mut *guardptr }; + let guard = unsafe { &mut *(&mut ph.g as *mut Option<_>) }; + debug_assert!(guard.is_none()); let idle = { let inner = guard.insert(self.inner.lock().await); @@ -336,7 +334,7 @@ impl<'a> EmbassySunset<'a> { // Safety: No borrows of guard remain, can lose the inferred 'f lifetime. // Not required after polonius. #[cfg(not(feature = "try-polonius"))] - let guard = unsafe { &mut *guardptr }; + let guard = unsafe { &mut *(&mut ph.g as *mut Option<_>) }; // Drop the Mutex *guard = None;