Skip to content

Commit

Permalink
Only upgrade Arc twice
Browse files Browse the repository at this point in the history
  • Loading branch information
davidpdrsn committed Mar 15, 2021
1 parent f2e44f9 commit 33fd64e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
6 changes: 5 additions & 1 deletion tokio/src/io/driver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl Handle {

pub(crate) fn is_shutdown(&self) -> bool {
if let Some(inner) = self.inner.upgrade() {
inner.is_shutdown.load(Ordering::SeqCst)
inner.is_shutdown()
} else {
// if the inner type has been dropped then its `Drop` impl will have been called which
// sets `Inner.is_shutdown` to `true`. So therefore it must have been shutdown.
Expand Down Expand Up @@ -366,6 +366,10 @@ impl Inner {
pub(super) fn deregister_source(&self, source: &mut impl mio::event::Source) -> io::Result<()> {
self.registry.deregister(source)
}

pub(super) fn is_shutdown(&self) -> bool {
self.is_shutdown.load(Ordering::SeqCst)
}
}

impl Direction {
Expand Down
3 changes: 2 additions & 1 deletion tokio/src/io/driver/registration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ cfg_io_readiness! {
pin!(fut);

crate::future::poll_fn(|cx| {
if self.handle.inner().is_none() || self.handle.is_shutdown() {
let inner = self.handle.inner();
if inner.is_none() || inner.filter(|i| i.is_shutdown()).is_some() {
return Poll::Ready(Err(io::Error::new(io::ErrorKind::Other, "reactor gone")));
}

Expand Down

0 comments on commit 33fd64e

Please sign in to comment.