rust: init: update init
module to take allocation flags
This is the last component in the conversion for allocators to take allocation flags as parameters. Reviewed-by: Benno Lossin <benno.lossin@proton.me> Signed-off-by: Wedson Almeida Filho <walmeida@microsoft.com> Link: https://lore.kernel.org/r/20240328013603.206764-10-wedsonaf@gmail.com Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
This commit is contained in:
committed by
Miguel Ojeda
parent
cc41670e06
commit
c34aa00d1d
@ -53,7 +53,7 @@
|
||||
//! Arc::pin_init(pin_init!(MyStruct {
|
||||
//! value,
|
||||
//! work <- new_work!("MyStruct::work"),
|
||||
//! }))
|
||||
//! }), GFP_KERNEL)
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
@ -101,7 +101,7 @@
|
||||
//! value_2,
|
||||
//! work_1 <- new_work!("MyStruct::work_1"),
|
||||
//! work_2 <- new_work!("MyStruct::work_2"),
|
||||
//! }))
|
||||
//! }), GFP_KERNEL)
|
||||
//! }
|
||||
//! }
|
||||
//!
|
||||
@ -132,6 +132,7 @@
|
||||
//!
|
||||
//! C header: [`include/linux/workqueue.h`](srctree/include/linux/workqueue.h)
|
||||
|
||||
use crate::alloc::Flags;
|
||||
use crate::{bindings, prelude::*, sync::Arc, sync::LockClassKey, types::Opaque};
|
||||
use alloc::alloc::AllocError;
|
||||
use alloc::boxed::Box;
|
||||
@ -210,13 +211,17 @@ impl Queue {
|
||||
/// Tries to spawn the given function or closure as a work item.
|
||||
///
|
||||
/// This method can fail because it allocates memory to store the work item.
|
||||
pub fn try_spawn<T: 'static + Send + FnOnce()>(&self, func: T) -> Result<(), AllocError> {
|
||||
pub fn try_spawn<T: 'static + Send + FnOnce()>(
|
||||
&self,
|
||||
flags: Flags,
|
||||
func: T,
|
||||
) -> Result<(), AllocError> {
|
||||
let init = pin_init!(ClosureWork {
|
||||
work <- new_work!("Queue::try_spawn"),
|
||||
func: Some(func),
|
||||
});
|
||||
|
||||
self.enqueue(Box::pin_init(init).map_err(|_| AllocError)?);
|
||||
self.enqueue(Box::pin_init(init, flags).map_err(|_| AllocError)?);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user