diff options
| author | Grant Miller <[email protected]> | 2022-07-25 22:30:01 -0500 |
|---|---|---|
| committer | Grant Miller <[email protected]> | 2022-07-25 22:30:01 -0500 |
| commit | 41e392bda30feae7e57f32872be082b1f15392ac (patch) | |
| tree | 05cc8464b53da4e716c9e860acac4dc40d5e6464 | |
| parent | 84cffc751ac0a38e6736959e68d441b99138d6d0 (diff) | |
Use `Forever::put_with` inside `Forever::put`
| -rw-r--r-- | embassy/src/util/forever.rs | 15 |
1 files changed, 1 insertions, 14 deletions
diff --git a/embassy/src/util/forever.rs b/embassy/src/util/forever.rs index ba3c66a91..4c2620052 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. |
