diff options
| -rw-r--r-- | embassy/src/util/forever.rs | 28 |
1 files changed, 5 insertions, 23 deletions
diff --git a/embassy/src/util/forever.rs b/embassy/src/util/forever.rs index ba3c66a91..3d2af38b1 100644 --- a/embassy/src/util/forever.rs +++ b/embassy/src/util/forever.rs | |||
| @@ -52,20 +52,7 @@ impl<T> Forever<T> { | |||
| 52 | #[inline(always)] | 52 | #[inline(always)] |
| 53 | #[allow(clippy::mut_from_ref)] | 53 | #[allow(clippy::mut_from_ref)] |
| 54 | pub fn put(&'static self, val: T) -> &'static mut T { | 54 | pub fn put(&'static self, val: T) -> &'static mut T { |
| 55 | if self | 55 | self.put_with(|| val) |
| 56 | .used | ||
| 57 | .compare_exchange(false, true, Ordering::Relaxed, Ordering::Relaxed) | ||
| 58 | .is_err() | ||
| 59 | { | ||
| 60 | panic!("Forever::put() called multiple times"); | ||
| 61 | } | ||
| 62 | |||
| 63 | unsafe { | ||
| 64 | let p = self.t.get(); | ||
| 65 | let p = (&mut *p).as_mut_ptr(); | ||
| 66 | p.write(val); | ||
| 67 | &mut *p | ||
| 68 | } | ||
| 69 | } | 56 | } |
| 70 | 57 | ||
| 71 | /// Store the closure return value in this `Forever`, returning a mutable reference to it. | 58 | /// Store the closure return value in this `Forever`, returning a mutable reference to it. |
| @@ -87,12 +74,8 @@ impl<T> Forever<T> { | |||
| 87 | panic!("Forever.put() called multiple times"); | 74 | panic!("Forever.put() called multiple times"); |
| 88 | } | 75 | } |
| 89 | 76 | ||
| 90 | unsafe { | 77 | let p: &'static mut MaybeUninit<T> = unsafe { &mut *self.t.get() }; |
| 91 | let p = self.t.get(); | 78 | p.write(val()) |
| 92 | let p = (&mut *p).as_mut_ptr(); | ||
| 93 | p.write(val()); | ||
| 94 | &mut *p | ||
| 95 | } | ||
| 96 | } | 79 | } |
| 97 | 80 | ||
| 98 | /// Unsafely get a mutable reference to the contents of this Forever. | 81 | /// Unsafely get a mutable reference to the contents of this Forever. |
| @@ -106,8 +89,7 @@ impl<T> Forever<T> { | |||
| 106 | #[inline(always)] | 89 | #[inline(always)] |
| 107 | #[allow(clippy::mut_from_ref)] | 90 | #[allow(clippy::mut_from_ref)] |
| 108 | pub unsafe fn steal(&self) -> &mut T { | 91 | pub unsafe fn steal(&self) -> &mut T { |
| 109 | let p = self.t.get(); | 92 | let p: &mut MaybeUninit<T> = &mut *self.t.get(); |
| 110 | let p = (&mut *p).as_mut_ptr(); | 93 | p.assume_init_mut() |
| 111 | &mut *p | ||
| 112 | } | 94 | } |
| 113 | } | 95 | } |
