Skip to content

Commit

Permalink
reset woken of outer future after polled
Browse files Browse the repository at this point in the history
  • Loading branch information
suikammd committed Oct 8, 2021
1 parent f0cb360 commit d1cc6af
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions tokio/src/runtime/basic_scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use std::cell::RefCell;
use std::collections::VecDeque;
use std::fmt;
use std::future::Future;
use std::sync::atomic::Ordering::{AcqRel, Acquire, Release};
use std::sync::atomic::Ordering::{AcqRel, Release};
use std::sync::Arc;
use std::task::Poll::{Pending, Ready};
use std::time::Duration;
Expand Down Expand Up @@ -224,7 +224,7 @@ impl<P: Park> Inner<P> {
pin!(future);

'outer: loop {
if scheduler.spawner.was_woken() || !polled {
if scheduler.spawner.reset_woken() || !polled {
polled = true;
scheduler.stats.incr_poll_count();
if let Ready(v) = crate::coop::budget(|| future.as_mut().poll(&mut cx)) {
Expand Down Expand Up @@ -418,13 +418,12 @@ impl Spawner {
}

fn waker_ref(&self) -> WakerRef<'_> {
// clear the woken bit
self.shared.woken.swap(false, AcqRel);
waker_ref(&self.shared)
}

fn was_woken(&self) -> bool {
self.shared.woken.load(Acquire)
// reset woken to false and return original value
pub(crate) fn reset_woken(&self) -> bool {
self.shared.woken.swap(false, AcqRel)
}
}

Expand Down

0 comments on commit d1cc6af

Please sign in to comment.