aboutsummaryrefslogtreecommitdiff
path: root/arch/x86/lib/atomic.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/x86/lib/atomic.c')
-rw-r--r--arch/x86/lib/atomic.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/arch/x86/lib/atomic.c b/arch/x86/lib/atomic.c
new file mode 100644
index 000000000000..4b8f6b842be9
--- /dev/null
+++ b/arch/x86/lib/atomic.c
@@ -0,0 +1,22 @@
+#include <linux/module.h>
+#include <asm/atomic.h>
+
+/**
+ * __arch_atomic_add_unless - add unless the number is already a given value
+ * @v: pointer of type atomic_t
+ * @a: the amount to add to v...
+ * @u: ...unless v is equal to u.
+ *
+ * Atomically adds @a to @v, so long as @v was not already @u.
+ * Returns the old value of @v.
+ */
+int __arch_atomic_add_unless(atomic_t *v, int a, int u)
+{
+ int c = arch_atomic_read(v);
+ do {
+ if (unlikely(c == u))
+ break;
+ } while (!atomic_try_cmpxchg(v, &c, c + a));
+ return c;
+}
+EXPORT_SYMBOL(__arch_atomic_add_unless);