Re: [PATCH 05/22] rust: pin-init: change examples to the user-space version
From: Andreas Hindborg
Date: Wed Mar 05 2025 - 05:07:53 EST
"Benno Lossin" <benno.lossin@xxxxxxxxx> writes:
> Replace the examples in the documentation by the ones from the
> user-space version and introduce the standalone examples from the
> user-space version such as the `CMutex<T>` type.
>
> The `CMutex<T>` example from the pinned-init repository [1] is used in
> several documentation examples in the user-space version instead of the
> kernel `Mutex<T>` type (as it's not available). In order to split off
> the pin-init crate, all examples need to be free of kernel-specific
> types.
>
> Link: https://github.com/rust-for-Linux/pinned-init [1]
> Signed-off-by: Benno Lossin <benno.lossin@xxxxxxxxx>
> ---
> rust/pin-init/examples/big_struct_in_place.rs | 39 ++
> rust/pin-init/examples/error.rs | 27 ++
> rust/pin-init/examples/linked_list.rs | 161 ++++++++
> rust/pin-init/examples/mutex.rs | 209 ++++++++++
> rust/pin-init/examples/pthread_mutex.rs | 178 +++++++++
> rust/pin-init/examples/static_init.rs | 122 ++++++
Do I need to review all these data structures and algorithms?
[...]
> @@ -76,28 +84,34 @@
> //! above method only works for types where you can access the fields.
> //!
> //! ```rust,ignore
> -//! # use kernel::sync::{new_mutex, Arc, Mutex};
> -//! let mtx: Result<Arc<Mutex<usize>>> =
> -//! Arc::pin_init(new_mutex!(42, "example::mtx"), GFP_KERNEL);
> +//! # #![feature(allocator_api)]
> +//! # #[path = "../examples/mutex.rs"] mod mutex; use mutex::*;
> +//! # use pin_init::*;
> +//! # use std::sync::Arc;
> +//! # use core::pin::Pin;
> +//! let mtx: Result<Pin<Arc<Mutex<usize>>>, _> = Arc::pin_init(CMutex::new(42));
> //! ```
Should this be `CMutex<_>` on the lhs?
Best regards,
Andreas Hindborg