Re: [RFC][PATCH] locking/refcount: Provide __refcount API to obtain the old value

From: David Howells
Date: Tue Jan 26 2021 - 06:46:11 EST


Will Deacon <will@xxxxxxxxxx> wrote:

> > @@ -219,9 +235,14 @@ static inline void refcount_add(int i, r
> > *
> > * Return: true if the increment was successful, false otherwise
> > */
> > +static inline __must_check bool __refcount_inc_not_zero(refcount_t *r, int *oldp)
> > +{
> > + return __refcount_add_not_zero(1, r, oldp);
> > +}
>
> Where returning both a bool to indicate whether the old value was zero
> and also the old value itself is a bit OTT.

Actually, with the i386 cmpxchg, that makes sense. You can use the Z flag to
give you the bool, saving on checking the old value.

David