[PATCH] locking: Generic ticket lock

Boqun Feng boqun.feng at gmail.com
Fri Oct 22 08:19:17 PDT 2021


On Thu, Oct 21, 2021 at 02:04:55PM -0400, Waiman Long wrote:
[...]
> > +static __always_inline int ticket_is_contended(arch_spinlock_t *lock)
> > +{
> > +	u32 val = atomic_read(lock);
> > +
> > +	return (__ticket(val) - __owner(val)) > 1;
> Nit: The left side is unsigned, but the right is signed. I think you are
> relying on the implicit signed to unsigned conversion. It may be a bit
> clearer if you use 1U instead.
> > +}
> > +
> > +static __always_inline int ticket_is_locked(arch_spinlock_t *lock)
> > +{
> > +	return __ticket_is_locked(atomic_read(lock));
> > +}
> > +
> > +static __always_inline int ticket_value_unlocked(arch_spinlock_t lock)
> > +{
> > +	return !__ticket_is_locked(lock.counter);
> > +}
> > +
> > +#undef __owner
> > +#undef __ticket
> > +#undef ONE_TICKET
> > +
> > +#define arch_spin_lock(l)		ticket_lock(l)
> > +#define arch_spin_trylock(l)		ticket_trylock(l)
> > +#define arch_spin_unlock(l)		ticket_unlock(l)
> > +#define arch_spin_is_locked(l)		ticket_is_locked(l)
> > +#define arch_spin_is_contended(l)	ticket_is_contended(l)
> > +#define arch_spin_value_unlocked(l)	ticket_value_unlocked(l)
> > +
> > +#endif /* __ASM_GENERIC_TICKET_LOCK_H */
> 
> Other than the nit above, the patch looks good to me.
> 
> Reviewed-by: Waiman Long <longman at redhat.com>
> 

Same here ;-)

Reviewed-by: Boqun Feng <boqun.feng at gmail.com>

Regards,
Boqun



More information about the linux-riscv mailing list