[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Xen-devel] [PATCH v3 8/8] asm-x86/atomic.h: implement missing, add common prototypes
- implement missing functions atomic_{sub,inc,dec}_return(), atomic_add_unless() on X86 and also add prototypes for them in common <xen/atomic.h> - add missing macro atomic_xchg for X86 Signed-off-by: Corneliu ZUZU <czuzu@xxxxxxxxxxxxxxx> --- xen/include/asm-x86/atomic.h | 27 +++++++++++++++++++++++++++ xen/include/xen/atomic.h | 36 ++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) diff --git a/xen/include/asm-x86/atomic.h b/xen/include/asm-x86/atomic.h index 1729e29..101eded 100644 --- a/xen/include/asm-x86/atomic.h +++ b/xen/include/asm-x86/atomic.h @@ -126,6 +126,11 @@ static inline void atomic_sub(int i, atomic_t *v) : "ir" (i), "m" (*(volatile int *)&v->counter) ); } +static inline int atomic_sub_return(int i, atomic_t *v) +{ + return arch_fetch_and_add(&v->counter, -i) - i; +} + static inline int atomic_sub_and_test(int i, atomic_t *v) { unsigned char c; @@ -145,6 +150,11 @@ static inline void atomic_inc(atomic_t *v) : "m" (*(volatile int *)&v->counter) ); } +static inline int atomic_inc_return(atomic_t *v) +{ + return atomic_add_return(1, v); +} + static inline int atomic_inc_and_test(atomic_t *v) { unsigned char c; @@ -164,6 +174,11 @@ static inline void atomic_dec(atomic_t *v) : "m" (*(volatile int *)&v->counter) ); } +static inline int atomic_dec_return(atomic_t *v) +{ + return atomic_sub_return(1, v); +} + static inline int atomic_dec_and_test(atomic_t *v) { unsigned char c; @@ -186,4 +201,16 @@ static inline int atomic_add_negative(int i, atomic_t *v) return c; } +static inline int atomic_add_unless(atomic_t *v, int a, int u) +{ + int c, old; + + c = atomic_read(v); + while (c != u && (old = atomic_cmpxchg(v, c, c + a)) != c) + c = old; + return c; +} + +#define atomic_xchg(v, new) (xchg(&((v)->counter), new)) + #endif /* __ARCH_X86_ATOMIC__ */ diff --git a/xen/include/xen/atomic.h b/xen/include/xen/atomic.h index 6827468..529213e 100644 --- a/xen/include/xen/atomic.h +++ b/xen/include/xen/atomic.h @@ -111,6 +111,15 @@ static inline int atomic_add_return(int i, atomic_t *v); static inline void atomic_sub(int i, atomic_t *v); /** + * atomic_sub_return - sub integer and return + * @i: integer value to sub + * @v: pointer of type atomic_t + * + * Atomically subtracts @i from @v and returns @v - @i. + */ +static inline int atomic_sub_return(int i, atomic_t *v); + +/** * atomic_sub_and_test - subtract value from variable and test result * @i: integer value to subtract * @v: pointer of type atomic_t @@ -130,6 +139,14 @@ static inline int atomic_sub_and_test(int i, atomic_t *v); static inline void atomic_inc(atomic_t *v); /** + * atomic_inc_return - increment atomic variable and return + * @v: pointer of type atomic_t + * + * Atomically increments @v by 1 and returns @v + 1. + */ +static inline int atomic_inc_return(atomic_t *v); + +/** * atomic_inc_and_test - increment and test * @v: pointer of type atomic_t * @@ -148,6 +165,14 @@ static inline int atomic_inc_and_test(atomic_t *v); static inline void atomic_dec(atomic_t *v); /** + * atomic_dec_return - decrement atomic variable and return + * @v: pointer of type atomic_t + * + * Atomically decrements @v by 1 and returns @v - 1. + */ +static inline int atomic_dec_return(atomic_t *v); + +/** * atomic_dec_and_test - decrement and test * @v: pointer of type atomic_t * @@ -168,4 +193,15 @@ static inline int atomic_dec_and_test(atomic_t *v); */ static inline int atomic_add_negative(int i, atomic_t *v); +/** + * atomic_add_unless - add to atomic variable unless it has a specified value + * @v: pointer of type atomic_t + * @a: integer value to add + * @u: integer value @v must -not- be for the add to be performed + * + * If @v != @u, adds @a to @v and returns @v + @a. + * Otherwise returns @u (== @v). + */ +static inline int atomic_add_unless(atomic_t *v, int a, int u); + #endif /* __XEN_ATOMIC_H__ */ -- 2.5.0 _______________________________________________ Xen-devel mailing list Xen-devel@xxxxxxxxxxxxx https://lists.xen.org/xen-devel
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |