Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: lock: Pin the inner data

In preparation to support Lock<T> where T is pinned, the first thing
that needs to be done is to structurally pin the 'data' member. This
switches the 't' parameter in Lock<T>::new() to take in an impl
PinInit<T> instead of a plain T. This in turn uses the blanket
implementation "impl PinInit<T> for T".

Subsequent patches will touch on Guard<T>.

Suggested-by: Benno Lossin <lossin@kernel.org>
Suggested-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Boqun Feng <boqun.feng@gmail.com>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Reviewed-by: Benno Lossin <lossin@kernel.org>
Reviewed-by: Alice Ryhl <aliceryhl@google.com>
Link: https://github.com/Rust-for-Linux/linux/issues/1181

authored by

Daniel Almeida and committed by
Peter Zijlstra
2497a711 da123f0e

+8 -3
+8 -3
rust/kernel/sync/lock.rs
··· 11 11 types::{NotThreadSafe, Opaque, ScopeGuard}, 12 12 }; 13 13 use core::{cell::UnsafeCell, marker::PhantomPinned, pin::Pin}; 14 - use pin_init::{pin_data, pin_init, PinInit}; 14 + use pin_init::{pin_data, pin_init, PinInit, Wrapper}; 15 15 16 16 pub mod mutex; 17 17 pub mod spinlock; ··· 115 115 _pin: PhantomPinned, 116 116 117 117 /// The data protected by the lock. 118 + #[pin] 118 119 pub(crate) data: UnsafeCell<T>, 119 120 } 120 121 ··· 128 127 129 128 impl<T, B: Backend> Lock<T, B> { 130 129 /// Constructs a new lock initialiser. 131 - pub fn new(t: T, name: &'static CStr, key: Pin<&'static LockClassKey>) -> impl PinInit<Self> { 130 + pub fn new( 131 + t: impl PinInit<T>, 132 + name: &'static CStr, 133 + key: Pin<&'static LockClassKey>, 134 + ) -> impl PinInit<Self> { 132 135 pin_init!(Self { 133 - data: UnsafeCell::new(t), 136 + data <- UnsafeCell::pin_init(t), 134 137 _pin: PhantomPinned, 135 138 // SAFETY: `slot` is valid while the closure is called and both `name` and `key` have 136 139 // static lifetimes so they live indefinitely.