atomic: Provide atomic_{or,xor,and}
authorPeter Zijlstra <peterz@infradead.org>
Wed, 23 Apr 2014 17:32:50 +0000 (19:32 +0200)
committerThomas Gleixner <tglx@linutronix.de>
Mon, 27 Jul 2015 12:06:24 +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.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
29 files changed:
arch/alpha/include/asm/atomic.h
arch/arc/include/asm/atomic.h
arch/arm/include/asm/atomic.h
arch/arm64/include/asm/atomic.h
arch/avr32/include/asm/atomic.h
arch/blackfin/include/asm/atomic.h
arch/frv/include/asm/atomic.h
arch/h8300/include/asm/atomic.h
arch/hexagon/include/asm/atomic.h
arch/ia64/include/asm/atomic.h
arch/m32r/include/asm/atomic.h
arch/m68k/include/asm/atomic.h
arch/metag/include/asm/atomic_lnkget.h
arch/mips/include/asm/atomic.h
arch/mn10300/include/asm/atomic.h
arch/parisc/include/asm/atomic.h
arch/powerpc/include/asm/atomic.h
arch/s390/include/asm/atomic.h
arch/sh/include/asm/atomic-grb.h
arch/sparc/include/asm/atomic_32.h
arch/sparc/include/asm/atomic_64.h
arch/tile/include/asm/atomic_32.h
arch/tile/include/asm/atomic_64.h
arch/x86/include/asm/atomic.h
arch/xtensa/include/asm/atomic.h
include/asm-generic/atomic.h
include/asm-generic/atomic64.h
include/linux/atomic.h
lib/atomic64.c

index 0eff853398d21e7782c06c8a25e136bc82cda2c6..e8c95609842436771f6c7c024c7b2830706987e8 100644 (file)
@@ -110,7 +110,6 @@ static __inline__ long atomic64_##op##_return(long i, atomic64_t * v)       \
 ATOMIC_OPS(add)
 ATOMIC_OPS(sub)
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
 #define atomic_andnot atomic_andnot
 #define atomic64_andnot atomic64_andnot
 
index e90b701fc6a87fc5b70741b7d60f603f0fe6b087..2a847821dee1a9a456378a209478d6bd089456a7 100644 (file)
@@ -144,7 +144,6 @@ static inline int atomic_##op##_return(int i, atomic_t *v)          \
 ATOMIC_OPS(add, +=, add)
 ATOMIC_OPS(sub, -=, sub)
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
 #define atomic_andnot atomic_andnot
 
 ATOMIC_OP(and, &=, and)
index ff214bac9cb4c5fa5a33ad0927dbbe76bed6728c..82b75a7cb7627481f0910e00f8be188e5dad1c33 100644 (file)
@@ -194,7 +194,6 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
 ATOMIC_OPS(add, +=, add)
 ATOMIC_OPS(sub, -=, sub)
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
 #define atomic_andnot atomic_andnot
 
 ATOMIC_OP(and, &=, and)
index 2876173397b28bc7ed66b484c92930f3915a4fbe..866a71fca9a3c493f9f7c0f7e9bbb80baa49a1e8 100644 (file)
@@ -85,7 +85,6 @@ static inline int atomic_##op##_return(int i, atomic_t *v)            \
 ATOMIC_OPS(add, add)
 ATOMIC_OPS(sub, sub)
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
 #define atomic_andnot atomic_andnot
 
 ATOMIC_OP(and, and)
index 115d3005e4bc1d00a9e173d494016cdbdf80a617..97c9bdf8340962209dfe09354175acb1eead01f8 100644 (file)
@@ -51,8 +51,6 @@ static inline void atomic_##op(int i, atomic_t *v)                    \
        (void)__atomic_##op##_return(i, v);                             \
 }
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC_OP(and, and)
 ATOMIC_OP(or, or)
 ATOMIC_OP(xor, eor)
index eafa55b81a7b6953d15f80ec5ee07d5263e04075..2d6a7a3823c3cf269490e7711b90685c9d290e40 100644 (file)
@@ -28,8 +28,6 @@ asmlinkage int __raw_atomic_test_asm(const volatile int *ptr, int value);
 #define atomic_add_return(i, v) __raw_atomic_add_asm(&(v)->counter, i)
 #define atomic_sub_return(i, v) __raw_atomic_add_asm(&(v)->counter, -(i))
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 #define atomic_or(i, v)  (void)__raw_atomic_or_asm(&(v)->counter, i)
 #define atomic_and(i, v) (void)__raw_atomic_and_asm(&(v)->counter, i)
 #define atomic_xor(i, v) (void)__raw_atomic_xor_asm(&(v)->counter, i)
index 74d22454d7c63d565cdb4e1dd0b5acd3f34f9ec7..fc48bea26b402596dbfe70fe74cfc8920914fac4 100644 (file)
@@ -192,8 +192,6 @@ static inline void atomic64_##op(long long i, atomic64_t *v)                \
        (void)__atomic64_fetch_##op(i, &v->counter);                    \
 }
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC_OP(or)
 ATOMIC_OP(and)
 ATOMIC_OP(xor)
index f181f820be332fbd90d44b2746d687d081c2be8c..c4d061f09c44db160b9ac0437be5a79e0d0d1dca 100644 (file)
@@ -41,8 +41,6 @@ static inline void atomic_##op(int i, atomic_t *v)            \
 ATOMIC_OP_RETURN(add, +=)
 ATOMIC_OP_RETURN(sub, -=)
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC_OP(and, &=)
 ATOMIC_OP(or,  |=)
 ATOMIC_OP(xor, ^=)
index 4efe2c7c0dd8679c18221236e9adbe27760fec3b..811d61f6422da107e9c4da9e03d02669eff1079b 100644 (file)
@@ -132,8 +132,6 @@ static inline int atomic_##op##_return(int i, atomic_t *v)          \
 ATOMIC_OPS(add)
 ATOMIC_OPS(sub)
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC_OP(and)
 ATOMIC_OP(or)
 ATOMIC_OP(xor)
index 0809ef5d6b9a107f625e8893936d676b47c79c0e..be4beeb77d57c2d2ca3a20de5ec61cfb18de38ad 100644 (file)
@@ -69,8 +69,6 @@ ATOMIC_OP(sub, -)
                : ia64_atomic_sub(__ia64_asr_i, v);                     \
 })
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC_OP(and, &)
 ATOMIC_OP(or, |)
 ATOMIC_OP(xor, ^)
index 7245463c1e98d560e4de047c35e52037387bb355..b2a13fbd5be0ea14933f3c4e0c65abb3a306c41c 100644 (file)
@@ -94,8 +94,6 @@ static __inline__ int atomic_##op##_return(int i, atomic_t *v)                \
 ATOMIC_OPS(add)
 ATOMIC_OPS(sub)
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC_OP(and)
 ATOMIC_OP(or)
 ATOMIC_OP(xor)
index c30e43ea49a3b8caf6c127db6ef2adc7525489e9..93ebd96aa494b2f10e6701012530e32db6bbc128 100644 (file)
@@ -77,8 +77,6 @@ static inline int atomic_##op##_return(int i, atomic_t * v)           \
 ATOMIC_OPS(add, +=, add)
 ATOMIC_OPS(sub, -=, sub)
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC_OP(and, &=, and)
 ATOMIC_OP(or, |=, or)
 ATOMIC_OP(xor, ^=, eor)
index 930c12cb8d378c6cc9f93ac976a01524c89b86ec..0642606de9012f7a30fc292adb433f69504f174f 100644 (file)
@@ -74,8 +74,6 @@ static inline int atomic_##op##_return(int i, atomic_t *v)            \
 ATOMIC_OPS(add)
 ATOMIC_OPS(sub)
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC_OP(and)
 ATOMIC_OP(or)
 ATOMIC_OP(xor)
index 0430ba6ab7628f4425890d5672ddb30be0e68c06..4c42fd9af7778462d18bea0724da19d2cdb35d4b 100644 (file)
@@ -137,8 +137,6 @@ static __inline__ int atomic_##op##_return(int i, atomic_t * v)                   \
 ATOMIC_OPS(add, +=, addu)
 ATOMIC_OPS(sub, -=, subu)
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC_OP(and, &=, and)
 ATOMIC_OP(or, |=, or)
 ATOMIC_OP(xor, ^=, xor)
index 03eea8158cf955330b332b0e34de0beb08d20aff..f5a63f0bda46203e5e024ffc40bc3da1c936cd73 100644 (file)
@@ -89,8 +89,6 @@ static inline int atomic_##op##_return(int i, atomic_t *v)            \
 ATOMIC_OPS(add)
 ATOMIC_OPS(sub)
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC_OP(and)
 ATOMIC_OP(or)
 ATOMIC_OP(xor)
index be2c50ddebd61d3edecda94d7471f9c35ca1de5d..2536965d00eae4c4a8c928a65b78471628cebf3d 100644 (file)
@@ -126,8 +126,6 @@ static __inline__ int atomic_##op##_return(int i, atomic_t *v)              \
 ATOMIC_OPS(add, +=)
 ATOMIC_OPS(sub, -=)
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC_OP(and, &=)
 ATOMIC_OP(or, |=)
 ATOMIC_OP(xor, ^=)
index 6ca89e2aca1591002275c9d4b4d808fbb2f8e22c..55f106ed12bf2e719f6f555c868cc5ba2a38da6a 100644 (file)
@@ -67,8 +67,6 @@ static __inline__ int atomic_##op##_return(int a, atomic_t *v)                \
 ATOMIC_OPS(add, add)
 ATOMIC_OPS(sub, subf)
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC_OP(and, and)
 ATOMIC_OP(or, or)
 ATOMIC_OP(xor, xor)
index b3859d8e001ff166636635629eed302e1546b4b4..d761aeff72da0805542f2cc65b150e8e545f5415 100644 (file)
@@ -282,8 +282,6 @@ static inline void atomic64_##op(long i, atomic64_t *v)                     \
        __ATOMIC64_LOOP(v, i, __ATOMIC64_##OP, __ATOMIC64_NO_BARRIER);  \
 }
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC64_OP(and, AND)
 ATOMIC64_OP(or, OR)
 ATOMIC64_OP(xor, XOR)
index 4b03830d48c730a206ac6b7250c93e452281dcb3..b94df40e5f2d2b701fdb7c0858b06ab745f6b65e 100644 (file)
@@ -48,8 +48,6 @@ static inline int atomic_##op##_return(int i, atomic_t *v)            \
 ATOMIC_OPS(add)
 ATOMIC_OPS(sub)
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC_OP(and)
 ATOMIC_OP(or)
 ATOMIC_OP(xor)
index e19d8880b14615d2c12a1aafc063761ef0221020..7dcbebbcaec6f0c742f941e580bc6564b1158c13 100644 (file)
@@ -17,8 +17,6 @@
 #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 *);
index d6af27c9345055d095a9d80726bafad17c290289..917084ace49dee70975f195a6c53d1d5c24af4ad 100644 (file)
@@ -33,8 +33,6 @@ 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)
index 94237922f0dd3eb1b090293c2820f71f15e98df9..d320ce253d8630d1dee48a366de0cf3b7823c0ab 100644 (file)
@@ -41,8 +41,6 @@ static inline void atomic_##op(int i, atomic_t *v)                    \
        _atomic_##op((unsigned long *)&v->counter, i);                  \
 }
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC_OP(and)
 ATOMIC_OP(or)
 ATOMIC_OP(xor)
index d07d9fc6e2a166807fd5b42e910d7953f79f8024..096a56d6ead429a2a0c06fd282a52e18a1d76a47 100644 (file)
@@ -58,8 +58,6 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
        return oldval;
 }
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 static inline void atomic_and(int i, atomic_t *v)
 {
        __insn_fetchand4((void *)&v->counter, i);
index f3a3ec0406946ecdff0cbb71ae1388a9a281a6bd..b3493023efdae0ba23784347ae17ebd5a4ae6cb5 100644 (file)
@@ -191,8 +191,6 @@ static inline void atomic_##op(int i, atomic_t *v)                  \
                        : "memory");                                    \
 }
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC_OP(and)
 ATOMIC_OP(or)
 ATOMIC_OP(xor)
index 4dd2450300a673a2fd6547b5394b8b2d2ff30dcf..31371f43c23bbdd9d054d84fe561367ba12d983f 100644 (file)
@@ -145,8 +145,6 @@ static inline int atomic_##op##_return(int i, atomic_t * v)         \
 ATOMIC_OPS(add)
 ATOMIC_OPS(sub)
 
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-
 ATOMIC_OP(and)
 ATOMIC_OP(or)
 ATOMIC_OP(xor)
index 92947e0a532a3580be8ee8459d13c898bd539429..a41b0b8f74049df6f59cbdabd0154f93d02568ce 100644 (file)
@@ -102,24 +102,27 @@ ATOMIC_OP_RETURN(sub, -)
 ATOMIC_OP(and, &)
 #endif
 
-#ifndef atomic_clear_mask
-#define atomic_clear_mask(i, v) atomic_and(~(i), (v))
-#endif
-
 #ifndef atomic_or
-#ifndef CONFIG_ARCH_HAS_ATOMIC_OR
-#define CONFIG_ARCH_HAS_ATOMIC_OR
-#endif
 ATOMIC_OP(or, |)
 #endif
 
-#ifndef atomic_set_mask
-#define atomic_set_mask(i, v)  atomic_or((i), (v))
+#ifndef atomic_xor
+ATOMIC_OP(xor, ^)
 #endif
 
 #undef ATOMIC_OP_RETURN
 #undef ATOMIC_OP
 
+static inline __deprecated void atomic_clear_mask(unsigned int mask, atomic_t *v)
+{
+       atomic_and(~mask, v);
+}
+
+static inline __deprecated void atomic_set_mask(unsigned int mask, atomic_t *v)
+{
+       atomic_or(mask, v);
+}
+
 /*
  * Atomic operations that C can't guarantee us.  Useful for
  * resource counting etc..
index 30ad9c86cebb62b1c695afb195fcdfb9ad027bee..d48e78ccad3dd8aedb3b020d46bdb00312c86772 100644 (file)
@@ -32,6 +32,10 @@ extern long long atomic64_##op##_return(long long a, atomic64_t *v);
 ATOMIC64_OPS(add)
 ATOMIC64_OPS(sub)
 
+ATOMIC64_OP(and)
+ATOMIC64_OP(or)
+ATOMIC64_OP(xor)
+
 #undef ATOMIC64_OPS
 #undef ATOMIC64_OP_RETURN
 #undef ATOMIC64_OP
index 5b08a8540ecfc3e6bcb5bf8b6fbef4d19df93f55..7d6279012a1fdab2d6c87611b2cc86340caa93d5 100644 (file)
@@ -111,19 +111,6 @@ static inline int atomic_dec_if_positive(atomic_t *v)
 }
 #endif
 
-#ifndef CONFIG_ARCH_HAS_ATOMIC_OR
-static inline void atomic_or(int i, atomic_t *v)
-{
-       int old;
-       int new;
-
-       do {
-               old = atomic_read(v);
-               new = old | i;
-       } while (atomic_cmpxchg(v, old, new) != old);
-}
-#endif /* #ifndef CONFIG_ARCH_HAS_ATOMIC_OR */
-
 #include <asm-generic/atomic-long.h>
 #ifdef CONFIG_GENERIC_ATOMIC64
 #include <asm-generic/atomic64.h>
index 1298c05ef52848ef3febd5e2512139c17533e844..2886ebac656772c8f77fe26f01d95175e0c18142 100644 (file)
@@ -102,6 +102,9 @@ EXPORT_SYMBOL(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