Messages in this thread | | | From | Arnd Bergmann <> | Subject | Re: [patch 04/36] Hexagon: Add atomic ops support | Date | Wed, 17 Aug 2011 21:20:36 +0200 |
| |
On Wednesday 17 August 2011 11:35:01 Richard Kuo wrote: > +/** > + * atomic_add_unless - add unless the number is a given value > + * @v: pointer to value > + * @a: amount to add > + * @u: unless value is equal to u > + * > + * This is actually in the asm-generic version; should revisit this > + * entire file... > + */ > +static inline int __atomic_add_unless(atomic_t *v, int a, int u) > +{ > + int c, old; > + > + c = atomic_read(v); > + for (;;) { > + if (unlikely(c == u)) > + break; > + old = atomic_cmpxchg((v), c, c + a); > + if (likely(old == c)) > + break; > + c = old; > + } > + return c != u; > +}
It's probably worth doing this in a single inline assembly instead of two nested loops (the second one being inside of atomic_cmpxchg.
Arnd
| |