[CRIU] [PATCH] atomic.h: make ARM version of atomic_set() return	the previous value of the atomic variable
    Alexander Kartashov 
    alekskartashov at parallels.com
       
    Tue Jan 29 01:47:24 EST 2013
    
    
  
From: Andrey Vagin <avagin at openvz.org>
Andrew Vagin proposed to make atomic_set() return the previous value
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;
-- 
1.7.10.4
    
    
More information about the CRIU
mailing list