diff options
Diffstat (limited to 'tokio/src/runtime/thread_pool/shutdown.rs')
-rw-r--r-- | tokio/src/runtime/thread_pool/shutdown.rs | 44 |
1 files changed, 0 insertions, 44 deletions
diff --git a/tokio/src/runtime/thread_pool/shutdown.rs b/tokio/src/runtime/thread_pool/shutdown.rs deleted file mode 100644 index 414c1c84..00000000 --- a/tokio/src/runtime/thread_pool/shutdown.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! A shutdown channel. -//! -//! Each worker holds the `Sender` half. When all the `Sender` halves are -//! dropped, the `Receiver` receives a notification. - -use crate::loom::sync::Arc; -use crate::sync::oneshot; - -#[derive(Debug, Clone)] -pub(super) struct Sender { - tx: Arc<oneshot::Sender<()>>, -} - -#[derive(Debug)] -pub(super) struct Receiver { - rx: oneshot::Receiver<()>, -} - -pub(super) fn channel() -> (Sender, Receiver) { - let (tx, rx) = oneshot::channel(); - let tx = Sender { tx: Arc::new(tx) }; - let rx = Receiver { rx }; - - (tx, rx) -} - -impl Receiver { - /// Blocks the current thread until all `Sender` handles drop. - pub(crate) fn wait(&mut self) { - use crate::runtime::enter::{enter, try_enter}; - - let mut e = if std::thread::panicking() { - match try_enter() { - Some(enter) => enter, - _ => return, - } - } else { - enter() - }; - - // The oneshot completes with an Err - let _ = e.block_on(&mut self.rx); - } -} |