Export fetch_or() that's implemented and used internally by the
scheduler. We are going to use it for NO_HZ so make it generally
available.
Cc: Christoph Lameter<cl@xxxxxxxxx>
Cc: Chris Metcalf<cmetcalf@xxxxxxxxxx>
Cc: Ingo Molnar<mingo@xxxxxxxxxx>
Cc: Luiz Capitulino<lcapitulino@xxxxxxxxxx>
Cc: Peter Zijlstra<peterz@xxxxxxxxxxxxx>
Cc: Rik van Riel<riel@xxxxxxxxxx>
Cc: Thomas Gleixner<tglx@xxxxxxxxxxxxx>
Cc: Viresh Kumar<viresh.kumar@xxxxxxxxxx>
Signed-off-by: Frederic Weisbecker<fweisbec@xxxxxxxxx>
---
include/linux/atomic.h | 18 ++++++++++++++++++
kernel/sched/core.c | 14 --------------
2 files changed, 18 insertions(+), 14 deletions(-)
diff --git a/include/linux/atomic.h b/include/linux/atomic.h
index 00a5763..c3b99f8 100644
--- a/include/linux/atomic.h
+++ b/include/linux/atomic.h
@@ -451,6 +451,24 @@ static inline int atomic_dec_if_positive(atomic_t *v)
}
#endif
+/**
+ * fetch_or - perform *ptr |= mask and return old value of *ptr
+ * @ptr: pointer to value
+ * @mask: mask to OR on the value
+ *
+ * cmpxchg based fetch_or, macro so it works for different integer types
+ */
+#define fetch_or(ptr, mask) \
+({ typeof(*(ptr)) __old, __val = *(ptr); \
+ for (;;) { \
+ __old = cmpxchg((ptr), __val, __val | (mask)); \
+ if (__old == __val) \
+ break; \
+ __val = __old; \
+ } \
+ __old; \
+})
+
#include <asm-generic/atomic-long.h>
#ifdef CONFIG_GENERIC_ATOMIC64
#include <asm-generic/atomic64.h>