Re: [PATCH 1/2] lib: Provide generic atomic64_t implementation

From: Arnd Bergmann
Date: Sat Jun 13 2009 - 17:54:21 EST

On Saturday 13 June 2009, Paul Mackerras wrote:
> +extern long long atomic64_read(const atomic64_t *v);
> +extern void atomic64_set(atomic64_t *v, long long i);
> +extern void atomic64_add(long long a, atomic64_t *v);
> +extern long long atomic64_add_return(long long a, atomic64_t *v);
> +extern void atomic64_sub(long long a, atomic64_t *v);
> +extern long long atomic64_sub_return(long long a, atomic64_t *v);
> +extern long long atomic64_dec_if_positive(atomic64_t *v);
> +extern long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n);
> +extern long long atomic64_xchg(atomic64_t *v, long long new);
> +extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
> +
> +#define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
> +#define atomic64_inc(v) atomic64_add(1LL, (v))
> +#define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
> +#define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
> +#define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
> +#define atomic64_dec(v) atomic64_sub(1LL, (v))
> +#define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
> +#define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
> +#define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
> +

How about also doing these:?

#define atomic64_sub(a, v) atomic64_add(-a, v)
#define atomic64_sub_return(a, v) atomic64_add_return(-a, v)
#define atomic64_add(a, v) (void)atomic64_add_return(a, v)

The cost to the caller (one or two instruction per call site)
seems to be about the same as for the other wrapper macros.

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
Please read the FAQ at