rust: workqueue: add #[pin_data]
to Work
The previous two patches made it possible to add `#[pin_data]` on structs with default generic parameter values. This patch makes `Work` use `#[pin_data]` and removes an invocation of `pin_init_from_closure`. This function is intended as a low level manual escape hatch, so it is better to rely on the safe `pin_init!` macro. Signed-off-by: Benno Lossin <benno.lossin@proton.me> Reviewed-by: Martin Rodriguez Reboredo <yakoyoku@gmail.com> Reviewed-by: Gary Guo <gary@garyguo.net> Reviewed-by: Alice Ryhl <aliceryhl@google.com> Tested-by: Alice Ryhl <aliceryhl@google.com> Link: https://lore.kernel.org/r/20240309155243.482334-3-benno.lossin@proton.me Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
parent
22eed6068d
commit
8db31d3f3b
@ -346,8 +346,10 @@ pub trait WorkItem<const ID: u64 = 0> {
|
|||||||
/// This is a helper type used to associate a `work_struct` with the [`WorkItem`] that uses it.
|
/// This is a helper type used to associate a `work_struct` with the [`WorkItem`] that uses it.
|
||||||
///
|
///
|
||||||
/// [`run`]: WorkItemPointer::run
|
/// [`run`]: WorkItemPointer::run
|
||||||
|
#[pin_data]
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
pub struct Work<T: ?Sized, const ID: u64 = 0> {
|
pub struct Work<T: ?Sized, const ID: u64 = 0> {
|
||||||
|
#[pin]
|
||||||
work: Opaque<bindings::work_struct>,
|
work: Opaque<bindings::work_struct>,
|
||||||
_inner: PhantomData<T>,
|
_inner: PhantomData<T>,
|
||||||
}
|
}
|
||||||
@ -369,21 +371,22 @@ impl<T: ?Sized, const ID: u64> Work<T, ID> {
|
|||||||
where
|
where
|
||||||
T: WorkItem<ID>,
|
T: WorkItem<ID>,
|
||||||
{
|
{
|
||||||
// SAFETY: The `WorkItemPointer` implementation promises that `run` can be used as the work
|
pin_init!(Self {
|
||||||
// item function.
|
work <- Opaque::ffi_init(|slot| {
|
||||||
unsafe {
|
// SAFETY: The `WorkItemPointer` implementation promises that `run` can be used as
|
||||||
kernel::init::pin_init_from_closure(move |slot| {
|
// the work item function.
|
||||||
let slot = Self::raw_get(slot);
|
unsafe {
|
||||||
bindings::init_work_with_key(
|
bindings::init_work_with_key(
|
||||||
slot,
|
slot,
|
||||||
Some(T::Pointer::run),
|
Some(T::Pointer::run),
|
||||||
false,
|
false,
|
||||||
name.as_char_ptr(),
|
name.as_char_ptr(),
|
||||||
key.as_ptr(),
|
key.as_ptr(),
|
||||||
);
|
)
|
||||||
Ok(())
|
}
|
||||||
})
|
}),
|
||||||
}
|
_inner: PhantomData,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get a pointer to the inner `work_struct`.
|
/// Get a pointer to the inner `work_struct`.
|
||||||
|
Loading…
Reference in New Issue
Block a user