diff options
Diffstat (limited to 'rust/kernel')
| -rw-r--r-- | rust/kernel/time.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs index 9327d803b9c7..53b77abcb317 100644 --- a/rust/kernel/time.rs +++ b/rust/kernel/time.rs @@ -295,6 +295,7 @@ mod private { pub trait Sealed {} impl Sealed for super::Nsec {} + impl Sealed for super::Jiffy {} } /// A trait for time units. @@ -314,6 +315,17 @@ impl TimeUnit for Nsec { type Repr = i64; } +/// A time unit of jiffies. +/// +/// A [`Delta<Jiffy>`] stores its value as [`isize`] jiffies and can represent +/// any [`isize`] value, including negative, zero, and positive numbers. +#[derive(Copy, Clone, PartialEq, PartialOrd, Eq, Ord, Debug)] +pub enum Jiffy {} + +impl TimeUnit for Jiffy { + type Repr = isize; +} + /// A span of time. /// /// The span is stored in the unit given by the type parameter `U` (see @@ -325,6 +337,20 @@ pub struct Delta<U: TimeUnit = Nsec> { value: U::Repr, } +impl Delta<Jiffy> { + /// Create a new [`Delta`] from a number of jiffies. + #[inline] + pub const fn from_jiffies(jiffies: isize) -> Self { + Self { value: jiffies } + } + + /// Return the number of jiffies in the [`Delta`]. + #[inline] + pub const fn as_jiffies(self) -> isize { + self.value + } +} + impl ops::Add for Delta { type Output = Self; |
