[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAH5fLgjk5koTwMOcdsnQjTVWQehjCDPoD2M3KboGZsxigKdMfA@mail.gmail.com>
Date: Wed, 16 Oct 2024 10:45:36 +0200
From: Alice Ryhl <aliceryhl@...gle.com>
To: FUJITA Tomonori <fujita.tomonori@...il.com>
Cc: netdev@...r.kernel.org, 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, 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: Re: [PATCH net-next v3 7/8] rust: Add read_poll_timeout functions
On Wed, Oct 16, 2024 at 5:54 AM FUJITA Tomonori
<fujita.tomonori@...il.com> wrote:
> +/// Polls periodically until a condition is met or a timeout is reached.
> +///
> +/// `op` is called repeatedly until `cond` returns `true` or the timeout is
> +/// reached. The return value of `op` is passed to `cond`.
> +///
> +/// `sleep_delta` is the duration to sleep between calls to `op`.
> +/// If `sleep_delta` is less than one microsecond, the function will busy-wait.
> +///
> +/// `timeout_delta` is the maximum time to wait for `cond` to return `true`.
> +///
> +/// This macro can only be used in a nonatomic context.
> +#[macro_export]
> +macro_rules! readx_poll_timeout {
> + ($op:expr, $cond:expr, $sleep_delta:expr, $timeout_delta:expr) => {{
> + #[cfg(CONFIG_DEBUG_ATOMIC_SLEEP)]
> + if !$sleep_delta.is_zero() {
> + // SAFETY: FFI call.
> + unsafe {
> + $crate::bindings::__might_sleep(
> + ::core::file!().as_ptr() as *const i8,
> + ::core::line!() as i32,
> + )
> + }
> + }
I wonder if we can use #[track_caller] and
core::panic::Location::caller [1] to do this without having to use a
macro? I don't know whether it would work, but if it does, that would
be super cool.
#[track_caller]
fn might_sleep() {
let location = core::panic::Location::caller();
// SAFETY: FFI call.
unsafe {
$crate::bindings::__might_sleep(
location.file().as_char_ptr(),
location.line() as i32,
)
}
}
Alice
[1]: https://doc.rust-lang.org/nightly/core/panic/struct.Location.html#method.caller
Powered by blists - more mailing lists