OpenCloudOS-Kernel/rust/kernel
Asahi Lina 31d95c2f99 rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init()
We can already create `UniqueArc<MaybeUninit<T>>` instances with
`UniqueArc::try_new_uninit()` and write to them with `write()`. Add
the missing unsafe `assume_init()` function to promote it to
`UniqueArc<T>`, so users can do piece-wise initialization of the
contents instead of doing it all at once as long as they keep the
invariants (the same requirements as `MaybeUninit::assume_init()`).

This mirrors the std `Arc::assume_init()` function. In the kernel,
since we have `UniqueArc`, arguably this only belongs there since most
use cases will initialize it immediately after creating it, before
demoting it to `Arc` to share it.

[ Miguel: The "Rust pin-init API for pinned initialization of structs"
  patch series [1] from Benno Lossin contains a very similar patch:

    rust: sync: add `assume_init` to `UniqueArc`

    Adds the `assume_init` function to `UniqueArc<MaybeUninit<T>>` that
    unsafely assumes the value to be initialized and yields a value of type
    `UniqueArc<T>`. This function is used when manually initializing the
    pointee of an `UniqueArc`.

  To make that patch a noop and thus drop it, I adjusted the `SAFETY`
  comment here to be the same as in the current latest version of
  that series (v7).

  I have also brought the `Reviewed-by`s there into here, and reworded
  the `Co-authored-by` into `Co-developed-by`. ]

Link: https://lore.kernel.org/r/20230408122429.1103522-5-y86-dev@protonmail.com [1]
Co-developed-by: Benno Lossin <benno.lossin@proton.me>
Signed-off-by: Benno Lossin <benno.lossin@proton.me>
Signed-off-by: Asahi Lina <lina@asahilina.net>
Reviewed-by: Gary Guo <gary@garyguo.net>
Reviewed-by: Wedson Almeida Filho <walmeida@microsoft.com>
Reviewed-by: Andreas Hindborg <a.hindborg@samsung.com>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://lore.kernel.org/r/20230224-rust-arc-v2-2-5c97a865b276@asahilina.net
Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
2023-04-12 18:41:04 +02:00
..
sync rust: sync: arc: Add UniqueArc<MaybeUninit<T>::assume_init() 2023-04-12 18:41:04 +02:00
allocator.rs rust: add `kernel` crate 2022-09-28 08:58:24 +02:00
build_assert.rs rust: build_assert: add `build_{error,assert}!` macros 2022-12-04 01:59:16 +01:00
error.rs rust: error: add `From` implementations for `Error` 2022-12-04 01:59:15 +01:00
lib.rs rust: Enable the new_uninit feature for kernel and driver crates 2023-04-10 05:21:15 +02:00
prelude.rs rust: prelude: prevent doc inline of external imports 2023-01-16 23:49:46 +01:00
print.rs rust: print: avoid evaluating arguments in `pr_*` macros in `unsafe` blocks 2023-01-16 00:54:35 +01:00
static_assert.rs rust: static_assert: add `static_assert!` macro 2022-12-04 01:59:16 +01:00
std_vendor.rs rust: std_vendor: add `dbg!` macro based on `std`'s one 2022-12-04 01:59:16 +01:00
str.rs rust: str: add `fmt!` macro 2022-12-04 01:59:16 +01:00
sync.rs rust: sync: introduce `UniqueArc` 2023-01-16 23:48:06 +01:00
types.rs rust: types: implement `ForeignOwnable` for the unit type 2023-02-01 13:24:36 +01:00