sparc: Provide atomic_{or,xor,and}
authorPeter Zijlstra <peterz@infradead.org>
Wed, 23 Apr 2014 17:40:25 +0000 (19:40 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Mon, 27 Jul 2015 12:06:23 +0000 (14:06 +0200)
Implement atomic logic ops -- atomic_{or,xor,and}.

These will replace the atomic_{set,clear}_mask functions that are
available on some archs.

Acked-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
arch/sparc/include/asm/atomic_32.h
arch/sparc/include/asm/atomic_64.h
arch/sparc/lib/atomic32.c
arch/sparc/lib/atomic_64.S
arch/sparc/lib/ksyms.c

index 0e69b7e7a439ce90e2f831c173fd67d55af53be0..e19d8880b14615d2c12a1aafc063761ef0221020 100644 (file)
 #include <asm/barrier.h>
 #include <asm-generic/atomic64.h>
 
+#define CONFIG_ARCH_HAS_ATOMIC_OR
 
 #define ATOMIC_INIT(i)  { (i) }
 
 int atomic_add_return(int, atomic_t *);
+void atomic_and(int, atomic_t *);
+void atomic_or(int, atomic_t *);
+void atomic_xor(int, atomic_t *);
 int atomic_cmpxchg(atomic_t *, int, int);
 int atomic_xchg(atomic_t *, int);
 int __atomic_add_unless(atomic_t *, int, int);
index 4082749913ce06109a3bd923e0bef4677d0376c9..d6af27c9345055d095a9d80726bafad17c290289 100644 (file)
@@ -33,6 +33,12 @@ long atomic64_##op##_return(long, atomic64_t *);
 ATOMIC_OPS(add)
 ATOMIC_OPS(sub)
 
+#define CONFIG_ARCH_HAS_ATOMIC_OR
+
+ATOMIC_OP(and)
+ATOMIC_OP(or)
+ATOMIC_OP(xor)
+
 #undef ATOMIC_OPS
 #undef ATOMIC_OP_RETURN
 #undef ATOMIC_OP
index 71cd65ab200c8739634447a995fb5e069cac3717..b9d63c0a7aabc2c726ff54c617f99bdb8b3ca74a 100644 (file)
@@ -27,22 +27,38 @@ static DEFINE_SPINLOCK(dummy);
 
 #endif /* SMP */
 
-#define ATOMIC_OP(op, cop)                                             \
+#define ATOMIC_OP_RETURN(op, c_op)                                     \
 int atomic_##op##_return(int i, atomic_t *v)                           \
 {                                                                      \
        int ret;                                                        \
        unsigned long flags;                                            \
        spin_lock_irqsave(ATOMIC_HASH(v), flags);                       \
                                                                        \
-       ret = (v->counter cop i);                                       \
+       ret = (v->counter c_op i);                                      \
                                                                        \
        spin_unlock_irqrestore(ATOMIC_HASH(v), flags);                  \
        return ret;                                                     \
 }                                                                      \
 EXPORT_SYMBOL(atomic_##op##_return);
 
-ATOMIC_OP(add, +=)
+#define ATOMIC_OP(op, c_op)                                            \
+void atomic_##op(int i, atomic_t *v)                                   \
+{                                                                      \
+       unsigned long flags;                                            \
+       spin_lock_irqsave(ATOMIC_HASH(v), flags);                       \
+                                                                       \
+       v->counter c_op i;                                              \
+                                                                       \
+       spin_unlock_irqrestore(ATOMIC_HASH(v), flags);                  \
+}                                                                      \
+EXPORT_SYMBOL(atomic_##op);
+
+ATOMIC_OP_RETURN(add, +=)
+ATOMIC_OP(and, &=)
+ATOMIC_OP(or, |=)
+ATOMIC_OP(xor, ^=)
 
+#undef ATOMIC_OP_RETURN
 #undef ATOMIC_OP
 
 int atomic_xchg(atomic_t *v, int new)
index 05dac43907d119ebb2f45037336e853f24068c2c..d6b0363f345bfbd41aeb4a7a287ee651404f2259 100644 (file)
@@ -47,6 +47,9 @@ ENDPROC(atomic_##op##_return);
 
 ATOMIC_OPS(add)
 ATOMIC_OPS(sub)
+ATOMIC_OP(and)
+ATOMIC_OP(or)
+ATOMIC_OP(xor)
 
 #undef ATOMIC_OPS
 #undef ATOMIC_OP_RETURN
@@ -84,6 +87,9 @@ ENDPROC(atomic64_##op##_return);
 
 ATOMIC64_OPS(add)
 ATOMIC64_OPS(sub)
+ATOMIC64_OP(and)
+ATOMIC64_OP(or)
+ATOMIC64_OP(xor)
 
 #undef ATOMIC64_OPS
 #undef ATOMIC64_OP_RETURN
index 1d649a95660c8cad57fbe90feadb7c43b9e8263f..bb600599726830a0e8465f8ab901147b52e2daec 100644 (file)
@@ -111,6 +111,9 @@ EXPORT_SYMBOL(atomic64_##op##_return);
 
 ATOMIC_OPS(add)
 ATOMIC_OPS(sub)
+ATOMIC_OP(and)
+ATOMIC_OP(or)
+ATOMIC_OP(xor)
 
 #undef ATOMIC_OPS
 #undef ATOMIC_OP_RETURN