Re: [PATCH v5 2/3] rust: sync: Introduce lock::Backend::Context

From: Benno Lossin
Date: Fri Sep 13 2024 - 10:14:50 EST


On 12.09.24 21:04, Lyude Paul wrote:
> Now that we've introduced an `IrqDisabled` token for marking contexts in
> which IRQs are disabled, we need a way to be able to pass it to locks that
> require that IRQs are disabled. In order to continue using the
> `lock::Backend` type instead of inventing our own thing, we accomplish this
> by adding the associated Context type, along with a `lock_with()` function
> that can accept a Context when acquiring a lock. To allow current users of
> context-less locks to keep using the normal `lock()` method, we take an
> example from Wedson Almeida Filho's work and add a `where T<'a>: Default`
> bound to `lock()` so that it can only be called on lock types where the
> context is simply a placeholder value, then re-implement it through the new
> `lock_with()` function.
>
> Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx>
>
> ---
>
> V3:
> * Use explicit lifetimes in lock_with() to ensure self and _context have
> the same lifetime (Benno)
> * Use () for locks that don't need a Context instead of PhantomData (Benno)
> V4:
> * Fix typo (Dirk)
>
> Signed-off-by: Lyude Paul <lyude@xxxxxxxxxx>

I don't think that you need your SOB twice.

> ---
> rust/kernel/sync/lock.rs | 17 +++++++++++++++--
> rust/kernel/sync/lock/mutex.rs | 1 +
> rust/kernel/sync/lock/spinlock.rs | 1 +
> 3 files changed, 17 insertions(+), 2 deletions(-)

This looks good:

Reviewed-by: Benno Lossin <benno.lossin@xxxxxxxxx>

---
Cheers,
Benno