Debian Codegraph @

src/event/sys/unix/waker/mio.rs

raw
1 use std::sync::{Arc, Mutex};
2
3 use ::mio::{Registry, Token};
4
5 /// Allows to wake up the `mio::Poll::poll()` method.
6 /// This type wraps `mio::Waker`, for more information see its documentation.
7 #[derive(Clone, Debug)]
8 pub(crate) struct Waker {
9 inner: Arc<Mutex<::mio::Waker>>,
10 }
11
12 impl Waker {
13 /// Create a new `Waker`.
14 pub(crate) fn new(registry: &Registry, waker_token: Token) -> std::io::Result<Self> {
15 Ok(Self {
16 inner: Arc::new(Mutex::new(mio::Waker::new(registry, waker_token)?)),
17 })
18 }
19
20 /// Wake up the [`Poll`] associated with this `Waker`.
21 ///
22 /// Readiness is set to `Ready::readable()`.
23 pub(crate) fn wake(&self) -> std::io::Result<()> {
24 self.inner.lock().unwrap().wake()
25 }
26
27 /// Resets the state so the same waker can be reused.
28 ///
29 /// This function is not impl
30 #[allow(dead_code, clippy::clippy::unnecessary_wraps)]
31 pub(crate) fn reset(&self) -> std::io::Result<()> {
32 Ok(())
33 }
34 }