Andreas Hindborg <nmi@xxxxxxxxxxxx> writes: > Maíra Canal <mcanal@xxxxxxxxxx> writes: > >> From: Asahi Lina <lina@xxxxxxxxxxxxx> >> >> The XArray is an abstract data type which behaves like a very large >> array of pointers. Add a Rust abstraction for this data type. >> >> The initial implementation uses explicit locking on get operations and >> returns a guard which blocks mutation, ensuring that the referenced >> object remains alive. To avoid excessive serialization, users are >> expected to use an inner type that can be efficiently cloned (such as >> Arc<T>), and eagerly clone and drop the guard to unblock other users >> after a lookup. >> >> Future variants may support using RCU instead to avoid mutex locking. >> >> This abstraction also introduces a reservation mechanism, which can be >> used by alloc-capable XArrays to reserve a free slot without immediately >> filling it, and then do so at a later time. If the reservation is >> dropped without being filled, the slot is freed again for other users, >> which eliminates the need for explicit cleanup code. >> >> Signed-off-by: Asahi Lina <lina@xxxxxxxxxxxxx> >> Co-developed-by: Maíra Canal <mcanal@xxxxxxxxxx> >> Signed-off-by: Maíra Canal <mcanal@xxxxxxxxxx> >> --- > > > Reviewed-by: Andreas Hindborg <a.hindborg@xxxxxxxxxxx> Actually clippy complains about use of the name `foo` for a variable in the example. Fix: diff --git a/rust/kernel/xarray.rs b/rust/kernel/xarray.rs index 849915ea633c..aba09cf28c4b 100644 --- a/rust/kernel/xarray.rs +++ b/rust/kernel/xarray.rs @@ -185,8 +185,8 @@ fn drop(&mut self) { /// let arr = Box::pin_init(XArray::<Arc<Foo>>::new(flags::ALLOC1)) /// .expect("Unable to allocate XArray"); /// -/// let foo = Arc::try_new(Foo { a : 1, b: 2 }).expect("Unable to allocate Foo"); -/// let index = arr.alloc(foo).expect("Error allocating Index"); +/// let item = Arc::try_new(Foo { a : 1, b: 2 }).expect("Unable to allocate Foo"); +/// let index = arr.alloc(item).expect("Error allocating Index"); /// /// if let Some(guard) = arr.get_locked(index) { /// assert_eq!(guard.borrow().a, 1); @@ -195,8 +195,8 @@ fn drop(&mut self) { /// pr_info!("No value found in index {}", index); /// } /// -/// let foo = Arc::try_new(Foo { a : 3, b: 4 }).expect("Unable to allocate Foo"); -/// let index = arr.alloc(foo).expect("Error allocating Index"); +/// let item = Arc::try_new(Foo { a : 3, b: 4 }).expect("Unable to allocate Foo"); +/// let index = arr.alloc(item).expect("Error allocating Index"); /// /// if let Some(removed_data) = arr.remove(index) { /// assert_eq!(removed_data.a, 3); BR Andreas