optimize interruptfuture
remove critical secitons, impl. Unpin
This commit is contained in:
parent
6503f9dbf5
commit
e0183f4495
@ -86,20 +86,17 @@ pub struct InterruptFuture<'a, I: OwnedInterrupt> {
|
|||||||
|
|
||||||
impl<'a, I: OwnedInterrupt> Drop for InterruptFuture<'a, I> {
|
impl<'a, I: OwnedInterrupt> Drop for InterruptFuture<'a, I> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
cortex_m::interrupt::free(|_| {
|
self.interrupt.disable();
|
||||||
self.interrupt.remove_handler();
|
self.interrupt.remove_handler();
|
||||||
self.interrupt.disable();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, I: OwnedInterrupt> InterruptFuture<'a, I> {
|
impl<'a, I: OwnedInterrupt> InterruptFuture<'a, I> {
|
||||||
pub fn new(interrupt: &'a mut I) -> Self {
|
pub fn new(interrupt: &'a mut I) -> Self {
|
||||||
cortex_m::interrupt::free(|_| {
|
interrupt.disable();
|
||||||
interrupt.set_handler(Self::interrupt_handler, ptr::null_mut());
|
interrupt.set_handler(Self::interrupt_handler, ptr::null_mut());
|
||||||
interrupt.unpend();
|
interrupt.unpend();
|
||||||
interrupt.enable();
|
interrupt.enable();
|
||||||
});
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
interrupt: interrupt,
|
interrupt: interrupt,
|
||||||
@ -120,22 +117,21 @@ impl<'a, I: OwnedInterrupt> InterruptFuture<'a, I> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<'a, I: OwnedInterrupt> Unpin for InterruptFuture<'a, I> {}
|
||||||
|
|
||||||
impl<'a, I: OwnedInterrupt> Future for InterruptFuture<'a, I> {
|
impl<'a, I: OwnedInterrupt> Future for InterruptFuture<'a, I> {
|
||||||
type Output = ();
|
type Output = ();
|
||||||
|
|
||||||
fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
|
fn poll(self: core::pin::Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> {
|
||||||
cortex_m::interrupt::free(|_| unsafe {
|
let s = unsafe { self.get_unchecked_mut() };
|
||||||
let s = self.get_unchecked_mut();
|
s.interrupt.set_handler(
|
||||||
if s.interrupt.is_enabled() {
|
Self::interrupt_handler,
|
||||||
s.interrupt.set_handler(
|
executor::raw::task_from_waker(&cx.waker()).cast().as_ptr(),
|
||||||
Self::interrupt_handler,
|
);
|
||||||
executor::raw::task_from_waker(&cx.waker()).cast().as_ptr(),
|
if s.interrupt.is_enabled() {
|
||||||
);
|
Poll::Pending
|
||||||
|
} else {
|
||||||
Poll::Pending
|
Poll::Ready(())
|
||||||
} else {
|
}
|
||||||
Poll::Ready(())
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user