-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rt: move deferred task list to scheduler (#5741)
Previously, the deferred task list (list of tasks that yielded and are waiting to be woken) was stored on the global runtime context. Because the scheduler is responsible for waking these tasks, it took additional TLS reads to perform the wake operation. Instead, this commit moves the list of deferred tasks into the scheduler context. This makes it easily accessible from the scheduler itself.
- Loading branch information
1 parent
a96dab1
commit c748f49
Showing
11 changed files
with
137 additions
and
133 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
use std::cell::RefCell; | ||
use std::task::Waker; | ||
|
||
pub(crate) struct Defer { | ||
deferred: RefCell<Vec<Waker>>, | ||
} | ||
|
||
impl Defer { | ||
pub(crate) fn new() -> Defer { | ||
Defer { | ||
deferred: Default::default(), | ||
} | ||
} | ||
|
||
pub(crate) fn defer(&self, waker: &Waker) { | ||
let mut deferred = self.deferred.borrow_mut(); | ||
|
||
// If the same task adds itself a bunch of times, then only add it once. | ||
if let Some(last) = deferred.last() { | ||
if last.will_wake(waker) { | ||
return; | ||
} | ||
} | ||
|
||
deferred.push(waker.clone()); | ||
} | ||
|
||
pub(crate) fn is_empty(&self) -> bool { | ||
self.deferred.borrow().is_empty() | ||
} | ||
|
||
pub(crate) fn wake(&self) { | ||
while let Some(waker) = self.deferred.borrow_mut().pop() { | ||
waker.wake(); | ||
} | ||
} | ||
|
||
#[cfg(tokio_taskdump)] | ||
pub(crate) fn take_deferred(&self) -> Vec<Waker> { | ||
let mut deferred = self.deferred.borrow_mut(); | ||
std::mem::take(&mut *deferred) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.