time: better docs explaining overflow handling.

This commit is contained in:
Dario Nieuwenhuis
2022-02-23 05:14:32 +01:00
parent 78795d6f56
commit fdb6e66b4b
2 changed files with 54 additions and 20 deletions

View File

@ -80,8 +80,15 @@ impl AlarmHandle {
/// Time driver
pub trait Driver: Send + Sync + 'static {
/// Return the current timestamp in ticks.
/// This is guaranteed to be monotonic, i.e. a call to now() will always return
/// a greater or equal value than earler calls.
///
/// Implementations MUST ensure that:
/// - This is guaranteed to be monotonic, i.e. a call to now() will always return
/// a greater or equal value than earler calls. Time can't "roll backwards".
/// - It "never" overflows. It must not overflow in a sufficiently long time frame, say
/// in 10_000 years (Human civilization is likely to already have self-destructed
/// 10_000 years from now.). This means if your hardware only has 16bit/32bit timers
/// you MUST extend them to 64-bit, for example by counting overflows in software,
/// or chaining multiple timers together.
fn now(&self) -> u64;
/// Try allocating an alarm handle. Returns None if no alarms left.