On Wed, May 18, 2016 at 04:10:59PM +0100, David Howells wrote: > +/** > + * __atomic_add_unless - add unless the number is already a given value > + * @v: pointer of type atomic_t > + * @a: the amount to add to v... > + * @u: ...unless v is equal to u. > + * > + * Atomically adds @a to @v, so long as @v was not already @u. > + * Returns the old value of @v. > + */ > +static __always_inline int __atomic_add_unless(atomic_t *v, > + int addend, int unless) > +{ > + int c = atomic_read(v); > + > + while (likely(c != unless)) { > + if (__atomic_compare_exchange_n(&v->counter, > + &c, c + addend, > + false, > + __ATOMIC_SEQ_CST, > + __ATOMIC_RELAXED)) > + break; > + } > + return c; > +} Does this generate 'sane' code for LL/SC archs? That is, a single LL/SC loop and not a loop around an LL/SC cmpxchg. -- To unsubscribe from this list: send the line "unsubscribe linux-arch" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html