Re: [patch 04/36] Hexagon: Add atomic ops support

From: Arnd Bergmann
Date: Wed Aug 17 2011 - 16:41:15 EST


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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/