Decrease lowres timer resolution to 5ms

This commit is contained in:
Nikolay Kim 2021-09-02 00:16:34 +06:00
parent a87c3855c8
commit 93463a673c
3 changed files with 12 additions and 6 deletions

View file

@ -1,5 +1,9 @@
# Changes # Changes
## [0.4.0-b.11] - 2021-09-01
* Decrease lowres timer resolution to 5ms
## [0.4.0-b.10] - 2021-09-01 ## [0.4.0-b.10] - 2021-09-01
* Fix lowres timer restart * Fix lowres timer restart

View file

@ -1,6 +1,6 @@
[package] [package]
name = "ntex" name = "ntex"
version = "0.4.0-b.10" version = "0.4.0-b.11"
authors = ["ntex contributors <team@ntex.rs>"] authors = ["ntex contributors <team@ntex.rs>"]
description = "Framework for composable network services" description = "Framework for composable network services"
readme = "README.md" readme = "README.md"

View file

@ -56,11 +56,13 @@ const fn lvl_offs(n: u64) -> u64 {
const WHEEL_TIMEOUT_CUTOFF: u64 = lvl_start(LVL_DEPTH); const WHEEL_TIMEOUT_CUTOFF: u64 = lvl_start(LVL_DEPTH);
const WHEEL_TIMEOUT_MAX: u64 = WHEEL_TIMEOUT_CUTOFF - (lvl_gran(LVL_DEPTH - 1)); const WHEEL_TIMEOUT_MAX: u64 = WHEEL_TIMEOUT_CUTOFF - (lvl_gran(LVL_DEPTH - 1));
const WHEEL_SIZE: usize = (LVL_SIZE as usize) * (LVL_DEPTH as usize); const WHEEL_SIZE: usize = (LVL_SIZE as usize) * (LVL_DEPTH as usize);
const ONE_MS: time::Duration = time::Duration::from_millis(1);
// Low res time resolution
const LOWRES_RESOLUTION: time::Duration = time::Duration::from_millis(5);
/// Returns an instant corresponding to “now”. /// Returns an instant corresponding to “now”.
/// ///
/// Resolution is ~1ms /// Resolution is ~5ms
#[inline] #[inline]
pub fn now() -> time::Instant { pub fn now() -> time::Instant {
TIMER.with(|t| t.0.borrow_mut().now(&t.0)) TIMER.with(|t| t.0.borrow_mut().now(&t.0))
@ -68,7 +70,7 @@ pub fn now() -> time::Instant {
/// Returns the system time corresponding to “now”. /// Returns the system time corresponding to “now”.
/// ///
/// Resolution is ~1ms /// Resolution is ~5ms
#[inline] #[inline]
pub fn system_time() -> time::SystemTime { pub fn system_time() -> time::SystemTime {
TIMER.with(|t| t.0.borrow().system_time()) TIMER.with(|t| t.0.borrow().system_time())
@ -617,7 +619,7 @@ impl LowresTimerDriver {
crate::rt::spawn(LowresTimerDriver { crate::rt::spawn(LowresTimerDriver {
inner: cell.clone(), inner: cell.clone(),
sleep: Box::pin(sleep_until(time::Instant::now() + ONE_MS)), sleep: Box::pin(sleep_until(time::Instant::now() + LOWRES_RESOLUTION)),
}); });
} }
} }
@ -647,7 +649,7 @@ impl Future for LowresTimerDriver {
} else { } else {
inner.flags.insert(Flags::LOWRES_TIMER); inner.flags.insert(Flags::LOWRES_TIMER);
drop(inner); drop(inner);
Pin::as_mut(&mut self.sleep).reset(time::Instant::now() + ONE_MS); Pin::as_mut(&mut self.sleep).reset(time::Instant::now() + LOWRES_RESOLUTION);
self.poll(cx) self.poll(cx)
} }
} }