Add signal reset()
This commit is contained in:
parent
def225b982
commit
a2735a716c
@ -26,8 +26,7 @@ impl<T: Send> Signal<T> {
|
||||
}
|
||||
|
||||
pub fn signal(&self, val: T) {
|
||||
unsafe {
|
||||
cortex_m::interrupt::free(|_| {
|
||||
cortex_m::interrupt::free(|_| unsafe {
|
||||
let state = &mut *self.state.get();
|
||||
match mem::replace(state, State::Signaled(val)) {
|
||||
State::Waiting(waker) => waker.wake(),
|
||||
@ -35,6 +34,12 @@ impl<T: Send> Signal<T> {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn reset(&self) {
|
||||
cortex_m::interrupt::free(|_| unsafe {
|
||||
let state = &mut *self.state.get();
|
||||
*state = State::None
|
||||
})
|
||||
}
|
||||
|
||||
pub fn wait<'a>(&'a self) -> impl Future<Output = T> + 'a {
|
||||
@ -50,8 +55,7 @@ impl<'a, T: Send> Future for WaitFuture<'a, T> {
|
||||
type Output = T;
|
||||
|
||||
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> {
|
||||
unsafe {
|
||||
cortex_m::interrupt::free(|_| {
|
||||
cortex_m::interrupt::free(|_| unsafe {
|
||||
let state = &mut *self.signal.state.get();
|
||||
match state {
|
||||
State::None => {
|
||||
@ -67,5 +71,4 @@ impl<'a, T: Send> Future for WaitFuture<'a, T> {
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user