tokio_threadpool/park/
default_park.rs1use tokio_executor::park::{Park, Unpark};
2
3use std::error::Error;
4use std::fmt;
5use std::time::Duration;
6
7use crossbeam_utils::sync::{Parker, Unparker};
8
9#[derive(Debug)]
11pub struct DefaultPark {
12 inner: Parker,
13}
14
15#[derive(Debug)]
17pub struct DefaultUnpark {
18 inner: Unparker,
19}
20
21#[derive(Debug)]
27pub struct ParkError {
28 _p: (),
29}
30
31impl DefaultPark {
34 pub fn new() -> DefaultPark {
36 DefaultPark {
37 inner: Parker::new(),
38 }
39 }
40
41 pub(crate) fn notify(&self) {
45 self.inner.unparker().unpark();
46 }
47
48 pub(crate) fn park_sync(&self, duration: Option<Duration>) {
49 match duration {
50 None => self.inner.park(),
51 Some(duration) => self.inner.park_timeout(duration),
52 }
53 }
54}
55
56impl Park for DefaultPark {
57 type Unpark = DefaultUnpark;
58 type Error = ParkError;
59
60 fn unpark(&self) -> Self::Unpark {
61 DefaultUnpark {
62 inner: self.inner.unparker().clone(),
63 }
64 }
65
66 fn park(&mut self) -> Result<(), Self::Error> {
67 self.inner.park();
68 Ok(())
69 }
70
71 fn park_timeout(&mut self, duration: Duration) -> Result<(), Self::Error> {
72 self.inner.park_timeout(duration);
73 Ok(())
74 }
75}
76
77impl Unpark for DefaultUnpark {
80 fn unpark(&self) {
81 self.inner.unpark();
82 }
83}
84
85impl fmt::Display for ParkError {
88 fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
89 self.description().fmt(fmt)
90 }
91}
92
93impl Error for ParkError {
94 fn description(&self) -> &str {
95 "unknown park error"
96 }
97}