diff options
| author | xoviat <[email protected]> | 2021-01-21 10:59:14 -0600 |
|---|---|---|
| committer | xoviat <[email protected]> | 2021-01-21 10:59:14 -0600 |
| commit | e0183f4495d937e1b11bd2ecb2871f42aac86c3e (patch) | |
| tree | eaf016d91b7204d705cf5d0277479fa5e8e77f9d | |
| parent | 6503f9dbf58c36d89b0f1bf9e70587905fbf3d07 (diff) | |
optimize interruptfuture
remove critical secitons, impl. Unpin
| -rw-r--r-- | embassy/src/util/signal.rs | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/embassy/src/util/signal.rs b/embassy/src/util/signal.rs index 28f86505e..2c9c52f1e 100644 --- a/embassy/src/util/signal.rs +++ b/embassy/src/util/signal.rs | |||
| @@ -86,20 +86,17 @@ pub struct InterruptFuture<'a, I: OwnedInterrupt> { | |||
| 86 | 86 | ||
| 87 | impl<'a, I: OwnedInterrupt> Drop for InterruptFuture<'a, I> { | 87 | impl<'a, I: OwnedInterrupt> Drop for InterruptFuture<'a, I> { |
| 88 | fn drop(&mut self) { | 88 | fn drop(&mut self) { |
| 89 | cortex_m::interrupt::free(|_| { | 89 | self.interrupt.disable(); |
| 90 | self.interrupt.remove_handler(); | 90 | self.interrupt.remove_handler(); |
| 91 | self.interrupt.disable(); | ||
| 92 | }); | ||
| 93 | } | 91 | } |
| 94 | } | 92 | } |
| 95 | 93 | ||
| 96 | impl<'a, I: OwnedInterrupt> InterruptFuture<'a, I> { | 94 | impl<'a, I: OwnedInterrupt> InterruptFuture<'a, I> { |
| 97 | pub fn new(interrupt: &'a mut I) -> Self { | 95 | pub fn new(interrupt: &'a mut I) -> Self { |
| 98 | cortex_m::interrupt::free(|_| { | 96 | interrupt.disable(); |
| 99 | interrupt.set_handler(Self::interrupt_handler, ptr::null_mut()); | 97 | interrupt.set_handler(Self::interrupt_handler, ptr::null_mut()); |
| 100 | interrupt.unpend(); | 98 | interrupt.unpend(); |
| 101 | interrupt.enable(); | 99 | interrupt.enable(); |
| 102 | }); | ||
| 103 | 100 | ||
| 104 | Self { | 101 | Self { |
| 105 | interrupt: interrupt, | 102 | interrupt: interrupt, |
| @@ -120,22 +117,21 @@ impl<'a, I: OwnedInterrupt> InterruptFuture<'a, I> { | |||
| 120 | } | 117 | } |
| 121 | } | 118 | } |
| 122 | 119 | ||
| 120 | impl<'a, I: OwnedInterrupt> Unpin for InterruptFuture<'a, I> {} | ||
| 121 | |||
| 123 | impl<'a, I: OwnedInterrupt> Future for InterruptFuture<'a, I> { | 122 | impl<'a, I: OwnedInterrupt> Future for InterruptFuture<'a, I> { |
| 124 | type Output = (); | 123 | type Output = (); |
| 125 | 124 | ||
| 126 | fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> { | 125 | fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> { |
| 127 | cortex_m::interrupt::free(|_| unsafe { | 126 | let s = unsafe { self.get_unchecked_mut() }; |
| 128 | let s = self.get_unchecked_mut(); | 127 | s.interrupt.set_handler( |
| 129 | if s.interrupt.is_enabled() { | 128 | Self::interrupt_handler, |
| 130 | s.interrupt.set_handler( | 129 | executor::raw::task_from_waker(&cx.waker()).cast().as_ptr(), |
| 131 | Self::interrupt_handler, | 130 | ); |
| 132 | executor::raw::task_from_waker(&cx.waker()).cast().as_ptr(), | 131 | if s.interrupt.is_enabled() { |
| 133 | ); | 132 | Poll::Pending |
| 134 | 133 | } else { | |
| 135 | Poll::Pending | 134 | Poll::Ready(()) |
| 136 | } else { | 135 | } |
| 137 | Poll::Ready(()) | ||
| 138 | } | ||
| 139 | }) | ||
| 140 | } | 136 | } |
| 141 | } | 137 | } |
