simplify ioctl waker code

This commit is contained in:
kbleeke 2023-03-27 12:40:27 +02:00
parent 6f547cf05d
commit 4c52104413

View File

@ -2,8 +2,6 @@ use core::cell::{Cell, RefCell};
use core::future::poll_fn; use core::future::poll_fn;
use core::task::{Poll, Waker}; use core::task::{Poll, Waker};
use embassy_sync::blocking_mutex::raw::NoopRawMutex;
use embassy_sync::blocking_mutex::Mutex;
use embassy_sync::waitqueue::WakerRegistration; use embassy_sync::waitqueue::WakerRegistration;
#[derive(Clone, Copy)] #[derive(Clone, Copy)]
@ -27,37 +25,39 @@ enum IoctlStateInner {
Done { resp_len: usize }, Done { resp_len: usize },
} }
#[derive(Default)]
struct Wakers {
control: WakerRegistration,
runner: WakerRegistration,
}
pub struct IoctlState { pub struct IoctlState {
state: Cell<IoctlStateInner>, state: Cell<IoctlStateInner>,
wakers: Mutex<NoopRawMutex, RefCell<(WakerRegistration, WakerRegistration)>>, wakers: RefCell<Wakers>,
} }
impl IoctlState { impl IoctlState {
pub fn new() -> Self { pub fn new() -> Self {
Self { Self {
state: Cell::new(IoctlStateInner::Done { resp_len: 0 }), state: Cell::new(IoctlStateInner::Done { resp_len: 0 }),
wakers: Mutex::new(RefCell::default()), wakers: Default::default(),
} }
} }
fn wake_control(&self) { fn wake_control(&self) {
self.wakers.lock(|f| { self.wakers.borrow_mut().control.wake();
f.borrow_mut().0.wake();
})
} }
fn register_control(&self, waker: &Waker) { fn register_control(&self, waker: &Waker) {
self.wakers.lock(|f| f.borrow_mut().0.register(waker)); self.wakers.borrow_mut().control.register(waker);
} }
fn wake_runner(&self) { fn wake_runner(&self) {
self.wakers.lock(|f| { self.wakers.borrow_mut().runner.wake();
f.borrow_mut().1.wake();
})
} }
fn register_runner(&self, waker: &Waker) { fn register_runner(&self, waker: &Waker) {
self.wakers.lock(|f| f.borrow_mut().1.register(waker)); self.wakers.borrow_mut().runner.register(waker);
} }
pub async fn wait_complete(&self) -> usize { pub async fn wait_complete(&self) -> usize {