Skip to content

Commit

Permalink
Use step_or_park from Timely (#70)
Browse files Browse the repository at this point in the history
This is the first step to remediate #51 without running the chance of accidentally slowing down useful work.

* Add until_next() method to scheduler
* Use step_or_park in server loop
  • Loading branch information
David Bach authored and comnik committed Apr 29, 2019
1 parent 33372f1 commit 86135cd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
6 changes: 4 additions & 2 deletions server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,10 @@ fn main() {
}

// ensure work continues, even if no queries registered,
// s.t. the sequencer continues issuing commands
worker.step();
// s.t. the sequencer continues issuing commands.
// If there is nothing to do, park `until_next()` activation
// in scheduler is ready.
worker.step_or_park(Some(server.scheduler.borrow().until_next().unwrap_or(Duration::from_millis(100))));

server.context.internal.advance().expect("failed to advance domain");

Expand Down
15 changes: 15 additions & 0 deletions src/server/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,21 @@ impl Scheduler {
false
}
}
/// Returns the duration until the next activation in `activator_queue`
/// from `now()`. If no activations are present returns None.
pub fn until_next(&self) -> Option<Duration> {
if let Some(ref timed_activator) = self.activator_queue.peek() {
// timed_activator.at.check_duration_since(Instant::now()).unwrap_or(Duration::from_millies(0))
let now = Instant::now();
if timed_activator.at > now {
Some(timed_activator.at.duration_since(now))
} else {
Some(Duration::from_millis(0))
}
} else {
None
}
}

/// Schedule activation at the specified instant. No hard
/// guarantees on when the activator will actually be triggered.
Expand Down

0 comments on commit 86135cd

Please sign in to comment.