aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/park.rs
diff options
context:
space:
mode:
authorJoel Galenson <jgalenson@google.com>2020-10-23 09:39:31 -0700
committerJoel Galenson <jgalenson@google.com>2020-10-23 09:52:09 -0700
commitd5495b03381a3ebe0805db353d198b285b535b5c (patch)
tree778b8524d15fca8b73db0253ee0e1919d0848bb6 /src/runtime/park.rs
parentba45c5bedf31df8562364c61d3dfb5262f10642e (diff)
downloadtokio-d5495b03381a3ebe0805db353d198b285b535b5c.tar.gz
Update to tokio-0.3.1 and add new features
Test: Build Change-Id: I5b5b9b386a21982a019653d0cf0bd3afc505cfac
Diffstat (limited to 'src/runtime/park.rs')
-rw-r--r--src/runtime/park.rs26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/runtime/park.rs b/src/runtime/park.rs
index ee437d1..033b9f2 100644
--- a/src/runtime/park.rs
+++ b/src/runtime/park.rs
@@ -6,7 +6,7 @@ use crate::loom::sync::atomic::AtomicUsize;
use crate::loom::sync::{Arc, Condvar, Mutex};
use crate::loom::thread;
use crate::park::{Park, Unpark};
-use crate::runtime::time;
+use crate::runtime::driver::Driver;
use crate::util::TryLock;
use std::sync::atomic::Ordering::SeqCst;
@@ -42,14 +42,14 @@ const NOTIFIED: usize = 3;
/// Shared across multiple Parker handles
struct Shared {
/// Shared driver. Only one thread at a time can use this
- driver: TryLock<time::Driver>,
+ driver: TryLock<Driver>,
/// Unpark handle
- handle: <time::Driver as Park>::Unpark,
+ handle: <Driver as Park>::Unpark,
}
impl Parker {
- pub(crate) fn new(driver: time::Driver) -> Parker {
+ pub(crate) fn new(driver: Driver) -> Parker {
let handle = driver.unpark();
Parker {
@@ -104,6 +104,10 @@ impl Park for Parker {
Ok(())
}
}
+
+ fn shutdown(&mut self) {
+ self.inner.shutdown();
+ }
}
impl Unpark for Unparker {
@@ -138,7 +142,7 @@ impl Inner {
fn park_condvar(&self) {
// Otherwise we need to coordinate going to sleep
- let mut m = self.mutex.lock().unwrap();
+ let mut m = self.mutex.lock();
match self
.state
@@ -176,7 +180,7 @@ impl Inner {
}
}
- fn park_driver(&self, driver: &mut time::Driver) {
+ fn park_driver(&self, driver: &mut Driver) {
match self
.state
.compare_exchange(EMPTY, PARKED_DRIVER, SeqCst, SeqCst)
@@ -234,7 +238,7 @@ impl Inner {
// Releasing `lock` before the call to `notify_one` means that when the
// parked thread wakes it doesn't get woken only to have to wait for us
// to release `lock`.
- drop(self.mutex.lock().unwrap());
+ drop(self.mutex.lock());
self.condvar.notify_one()
}
@@ -242,4 +246,12 @@ impl Inner {
fn unpark_driver(&self) {
self.shared.handle.unpark();
}
+
+ fn shutdown(&self) {
+ if let Some(mut driver) = self.shared.driver.try_lock() {
+ driver.shutdown();
+ }
+
+ self.condvar.notify_all();
+ }
}