Skip to content

feat(scheduler): Allow overlapping IoPauseGuards #4246

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl SchedulerState {
pub(crate) async fn start(&self, context: Context) {
let mut inner = self.inner.write().await;
inner.started = true;
if inner.scheduler.is_none() && !inner.paused {
if inner.scheduler.is_none() && inner.paused == 0 {
Self::do_start(inner, context).await;
}
}
Expand Down Expand Up @@ -99,15 +99,15 @@ impl SchedulerState {
pub(crate) async fn pause<'a>(&'_ self, context: Context) -> IoPausedGuard {
{
let mut inner = self.inner.write().await;
inner.paused = true;
inner.paused += 1;
Self::do_stop(inner, &context).await;
}
let (tx, rx) = oneshot::channel();
tokio::spawn(async move {
rx.await.ok();
let mut inner = context.scheduler.inner.write().await;
inner.paused = false;
if inner.started && inner.scheduler.is_none() {
inner.paused -= 1;
if inner.paused == 0 && inner.started && inner.scheduler.is_none() {
SchedulerState::do_start(inner, context.clone()).await;
}
});
Expand Down Expand Up @@ -199,8 +199,10 @@ impl SchedulerState {
#[derive(Debug, Default)]
struct InnerSchedulerState {
scheduler: Option<Scheduler>,
/// Whether IO should be started if there is no [`IoPausedGuard`] active.
started: bool,
paused: bool,
/// The number of [`IoPausedGuard`]s that are outstanding.
paused: u32,
}

/// Guard to make sure the IO Scheduler is resumed.
Expand Down