threadshare: Don't drift slowly when throttling the main context

Instead of taking a new time every iteration, take it once in the
beginning and add our wait time on every iteration. This prevents
accumulating errors and slowly drifting.
This commit is contained in:
Sebastian Dröge 2019-04-15 18:40:17 +03:00
parent 50b9654af5
commit f5b88d37c5

View file

@ -104,10 +104,10 @@ impl IOContextRunner {
let _ = sender.send(current_thread.handle());
let mut now = time::Instant::now();
::tokio_timer::with_default(&timer_handle, &mut enter, |mut enter| {
::tokio_reactor::with_default(&handle, &mut enter, |enter| loop {
let now = time::Instant::now();
if self.shutdown.load(atomic::Ordering::SeqCst) > RUNNING {
break;
}
@ -130,6 +130,7 @@ impl IOContextRunner {
);
thread::sleep(wait - elapsed);
}
now += wait;
})
});
}