From 4c521044131279aa36f7e21dbc6ec566703a57c6 Mon Sep 17 00:00:00 2001 From: kbleeke Date: Mon, 27 Mar 2023 12:40:27 +0200 Subject: [PATCH] simplify ioctl waker code --- src/ioctl.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/ioctl.rs b/src/ioctl.rs index 2d4cdb871..6a7465593 100644 --- a/src/ioctl.rs +++ b/src/ioctl.rs @@ -2,8 +2,6 @@ use core::cell::{Cell, RefCell}; use core::future::poll_fn; use core::task::{Poll, Waker}; -use embassy_sync::blocking_mutex::raw::NoopRawMutex; -use embassy_sync::blocking_mutex::Mutex; use embassy_sync::waitqueue::WakerRegistration; #[derive(Clone, Copy)] @@ -27,37 +25,39 @@ enum IoctlStateInner { Done { resp_len: usize }, } +#[derive(Default)] +struct Wakers { + control: WakerRegistration, + runner: WakerRegistration, +} + pub struct IoctlState { state: Cell, - wakers: Mutex>, + wakers: RefCell, } impl IoctlState { pub fn new() -> Self { Self { state: Cell::new(IoctlStateInner::Done { resp_len: 0 }), - wakers: Mutex::new(RefCell::default()), + wakers: Default::default(), } } fn wake_control(&self) { - self.wakers.lock(|f| { - f.borrow_mut().0.wake(); - }) + self.wakers.borrow_mut().control.wake(); } 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) { - self.wakers.lock(|f| { - f.borrow_mut().1.wake(); - }) + self.wakers.borrow_mut().runner.wake(); } 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 {