[CRIU] [PATCH] atomic.h: make ARM version of atomic_set() return the previous value of the atomic variable

Pavel Emelyanov xemul at parallels.com
Tue Jan 29 18:15:49 EST 2013


On 01/29/2013 10:47 AM, Alexander Kartashov wrote:
> From: Andrey Vagin <avagin at openvz.org>
> 
> Andrew Vagin proposed to make atomic_set() return the previous value

It's bad proposal. The function name should describe what it does. Find
out what's the kernel function doing what you want (atomic_get_and_set,
xchg?)and give your the same name.

> of the atomic variable on ARM. This may be useful e. g. to implement
> the check whether a locked mutex is being unlocked.
> 
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> CC: Cyrill Gorcunov <gorcunov at openvz.org>
> CC: Alexander Kartashov <alekskartashov at parallels.com>
> Acked-by: Alexander Kartashov <alekskartashov at parallels.com>
> ---
>  arch/arm/include/asm/atomic.h |   21 ++++++++++++++++++++-
>  1 file changed, 20 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
> index ccf6a7d..ad9da90 100644
> --- a/arch/arm/include/asm/atomic.h
> +++ b/arch/arm/include/asm/atomic.h
> @@ -10,9 +10,28 @@ typedef struct {
>  
>  #define smp_mb() __asm__ __volatile__ ("dmb" : : : "memory")
>  
> -#define atomic_set(mem,v) ((mem)->counter = (v))
>  #define atomic_get(v)	(*(volatile u32 *)&(v)->counter)
>  
> +static inline unsigned int atomic_set(atomic_t *v, int i)
> +{
> +	unsigned int result, tmp;
> +
> +	smp_mb();
> +
> +	__asm__ __volatile__("@ __xchg4\n"
> +"1:     ldrex   %0, [%3]\n"
> +"       strex   %1, %2, [%3]\n"
> +"       teq     %1, #0\n"
> +"       bne     1b"
> +	: "=&r" (result), "=&r" (tmp)
> +	: "r" (i), "r" (&v->counter)
> +	: "memory", "cc");
> +
> +	smp_mb();
> +
> +	return result;
> +}
> +
>  static inline unsigned int atomic_add_return(int i, atomic_t *v)
>  {
>  	unsigned long tmp;
> 




More information about the CRIU mailing list