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 7, 2021
1 parent d047584 commit 45661b2
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions tokio/src/runtime/basic_scheduler.rs
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 @@ -423,8 +423,9 @@ impl Spawner {
waker_ref(&self.shared)
}

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

Expand Down

0 comments on commit 45661b2

Please sign in to comment.