[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20241016035214.2229-5-fujita.tomonori@gmail.com>
Date: Wed, 16 Oct 2024 12:52:09 +0900
From: FUJITA Tomonori <fujita.tomonori@...il.com>
To: netdev@...r.kernel.org
Cc: rust-for-linux@...r.kernel.org,
andrew@...n.ch,
hkallweit1@...il.com,
tmgross@...ch.edu,
ojeda@...nel.org,
alex.gaynor@...il.com,
gary@...yguo.net,
bjorn3_gh@...tonmail.com,
benno.lossin@...ton.me,
a.hindborg@...sung.com,
aliceryhl@...gle.com,
anna-maria@...utronix.de,
frederic@...nel.org,
tglx@...utronix.de,
arnd@...db.de,
jstultz@...gle.com,
sboyd@...nel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH net-next v3 4/8] rust: time: Implement addition of Ktime and Delta
Implement Add<Delta> for Ktime to support the operation:
Ktime = Ktime + Delta
This is typically used to calculate the future time when the timeout
will occur.
timeout Ktime = current Ktime (via ktime_get()) + Delta;
// do something
if (ktime_get() > timeout Ktime) {
// timed out
}
Signed-off-by: FUJITA Tomonori <fujita.tomonori@...il.com>
---
rust/kernel/time.rs | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/rust/kernel/time.rs b/rust/kernel/time.rs
index 8c00854db58c..9b0537b63cf7 100644
--- a/rust/kernel/time.rs
+++ b/rust/kernel/time.rs
@@ -155,3 +155,14 @@ pub fn as_secs(self) -> i64 {
self.nanos / NSEC_PER_SEC
}
}
+
+impl core::ops::Add<Delta> for Ktime {
+ type Output = Ktime;
+
+ #[inline]
+ fn add(self, delta: Delta) -> Ktime {
+ Ktime {
+ inner: self.inner + delta.as_nanos(),
+ }
+ }
+}
--
2.43.0
Powered by blists - more mailing lists