Thread (63 messages) 63 messages, 5 authors, 2025-01-24

Re: [PATCH v8 4/7] rust: time: Add wrapper for fsleep function

From: Alice Ryhl <aliceryhl@google.com>
Date: 2025-01-17 09:13:22
Also in: lkml, rust-for-linux

On Fri, Jan 17, 2025 at 10:01 AM FUJITA Tomonori
[off-list ref] wrote:
On Fri, 17 Jan 2025 16:53:26 +0900 (JST)
FUJITA Tomonori [off-list ref] wrote:
quoted
On Thu, 16 Jan 2025 10:27:02 +0100
Alice Ryhl [off-list ref] wrote:
quoted
quoted
+/// This function can only be used in a nonatomic context.
+pub fn fsleep(delta: Delta) {
+    // The argument of fsleep is an unsigned long, 32-bit on 32-bit architectures.
+    // Considering that fsleep rounds up the duration to the nearest millisecond,
+    // set the maximum value to u32::MAX / 2 microseconds.
+    const MAX_DURATION: Delta = Delta::from_micros(u32::MAX as i64 >> 1);
Hmm, is this value correct on 64-bit platforms?
You meant that the maximum can be longer on 64-bit platforms? 2147484
milliseconds is long enough for fsleep's duration?

If you prefer, I use different maximum durations for 64-bit and 32-bit
platforms, respectively.
How about the following?

const MAX_DURATION: Delta = Delta::from_micros(usize::MAX as i64 >> 1);
Why is there a maximum in the first place? Are you worried about
overflow on the C side?

Alice
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help