[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCHv2 3/6] xen: generic xadd() for ticket locks



Provide a generic xadd() implementation for architectures that don't
provide one.

This is only temporary until arm/arm64 provides an xadd()
implementation.

Signed-off-by: David Vrabel <david.vrabel@xxxxxxxxxx>
---
 xen/common/spinlock.c |   21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/xen/common/spinlock.c b/xen/common/spinlock.c
index 5fd8b1c..0c4289c 100644
--- a/xen/common/spinlock.c
+++ b/xen/common/spinlock.c
@@ -10,6 +10,27 @@
 #include <asm/processor.h>
 #include <asm/atomic.h>
 
+#ifndef xadd
+
+static u32 generic_xaddl(volatile u32 *ptr, u32 v)
+{
+    u32 old, new, prev;
+
+    old = read_atomic(ptr);
+    for(;;) {
+        new = old + v;
+        prev = cmpxchg(ptr, old, new);
+        if (prev == old)
+            break;
+        old = prev;
+    }
+    return old;
+}
+
+#define xadd(ptr, v) generic_xaddl((ptr), (v))
+
+#endif
+
 #ifndef NDEBUG
 
 static atomic_t spin_debug __read_mostly = ATOMIC_INIT(0);
-- 
1.7.10.4


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.