Skip to contentSkip to conversation

inotify 0.22 2.4.x backport - atomic_inc_return

RFC PATCH New Mihai Rusu 1 participant 1 message May 10, 2005 Atomic infrastructure

lore
Share & tools
lore

Mihai Rusu

author
#0 lore raw

RFC PATCH 3/4 inotify 0.22 2.4.x backport - atomic_inc_return

Hi

Backported atomic_inc_return() from 2.6.11 for x86. Needed by inotify.c. I have not backported for other architectures as I don't have access to such devices and I could not test. It should be easy to do that tho. This also means that this inotify backport currently only works for x86.

Signature · 7 lines
Mihai Rusu
Linux System Development

Schlund + Partner AG   Tel         : +40-21-231-2544
Str Mircea Eliade 18   EMail       : [email protected]
Sect 1, Bucuresti
71295, Romania
 atomic.h |   34 ++++++++++++++++++++++++++++++++++
 1 files changed, 34 insertions(+)
include/asm-i386/atomic.h +34 -0
diff -uNr linux-2.4.30.orig/include/asm-i386/atomic.h linux-2.4.30/include/asm-i386/atomic.h
@@ -186,6 +186,40 @@
 	return c;
 }
 
+/**
+ * atomic_add_return - add and return
+ * @v: pointer of type atomic_t
+ * @i: integer value to add
+ *
+ * Atomically adds @i to @v and returns @i + @v
+ */
+static __inline__ int atomic_add_return(int i, atomic_t *v)
+{
+        int __i;
+#ifdef CONFIG_M386
+        if(unlikely(boot_cpu_data.x86==3))
+                goto no_xadd;
+#endif
+        /* Modern 486+ processor */
+        __i = i;
+        __asm__ __volatile__(
+                LOCK "xaddl %0, %1;"
+                :"=r"(i)
+                :"m"(v->counter), "0"(i));
+        return i + __i;
+
+#ifdef CONFIG_M386
+no_xadd: /* Legacy 386 processor */
+        local_irq_disable();
+        __i = atomic_read(v);
+        atomic_set(v, i + __i);
+        local_irq_enable();
+        return i + __i;
+#endif
+}
+
+#define atomic_inc_return(v)  (atomic_add_return(1,v))
+
 /* These are x86-specific, used by some header files */
 #define atomic_clear_mask(mask, addr) \
 __asm__ __volatile__(LOCK "andl %0,%1" \