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

From: Mihai Rusu
Date: Tue May 10 2005 - 10:24:18 EST


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.

--
Mihai Rusu
Linux System Development

Schlund + Partner AG Tel : +40-21-231-2544
Str Mircea Eliade 18 EMail : dizzy@xxxxxxxxxx
Sect 1, Bucuresti
71295, Romania



atomic.h | 34 ++++++++++++++++++++++++++++++++++
1 files changed, 34 insertions(+)


diff -uNr linux-2.4.30.orig/include/asm-i386/atomic.h linux-2.4.30/include/asm-i386/atomic.h
--- linux-2.4.30.orig/include/asm-i386/atomic.h 2001-11-22 21:46:18.000000000 +0200
+++ linux-2.4.30/include/asm-i386/atomic.h 2005-05-09 11:58:56.000000000 +0300
@@ -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" \