[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <OCjFF0---F-9@tuta.io>
Date: Wed, 27 Nov 2024 21:12:31 +0100 (CET)
From: jens.korinth@...a.io
To: Alice Ryhl <aliceryhl@...gle.com>
Cc: Miguel Ojeda <ojeda@...nel.org>, Alex Gaynor <alex.gaynor@...il.com>,
Boqun Feng <boqun.feng@...il.com>, Gary Guo <gary@...yguo.net>,
Björn Roy Baron <bjorn3_gh@...tonmail.com>,
Benno Lossin <benno.lossin@...ton.me>,
Andreas Hindborg <a.hindborg@...nel.org>,
Trevor Gross <tmgross@...ch.edu>,
Rust For Linux <rust-for-linux@...r.kernel.org>,
FUJITA Tomonori <fujita.tomonori@...il.com>,
Dirk Behme <dirk.behme@...il.com>,
Linux Kernel <linux-kernel@...r.kernel.org>
Subject: Re: [PATCH v4 1/3] rust: Add `OnceLite` for executing code once
> What is the use-case for this function?
`DO_ONCE_LITE` has very few uses in C; frankly, the only other use I could think
of was initialization. But since `OnceLite` cannot block or guarantee visibility
of the side-effects of the `call_once` expression in other threads, it can't be
used for this case, either. _Unless_ there is some mechanism to wait
voluntarily when this is required, hence `is_completed`. (And it also exists in
`std::sync::Once`.)
`DO_ONCE_LITE_IF` has more uses in C, but this is a bit harder to do well with
`OnceLite`: A `do_once_lite_if` Rust macro can't short-circuit the condition to
avoid the evaluation if the atomic load already shows that it has been done / is
being done rn. Maybe a
`pub fn call_once<C: FnOnce() -> bool, F: FnOnce()>(cond: C, f: F)` could be
used to simulate the effect. Thoughts?
> Why not just have one atomic?
Do you also have an `AtomicU32` state var in mind, as Daniel suggested?
Jens
Powered by blists - more mailing lists