[PATCH] make local_t signed
authorAndrew Morton <akpm@osdl.org>
Fri, 31 Mar 2006 10:30:49 +0000 (02:30 -0800)
committerLinus Torvalds <torvalds@g5.osdl.org>
Fri, 31 Mar 2006 20:18:55 +0000 (12:18 -0800)
local_t's were defined to be unsigned.  This increases confusion because
atomic_t's are signed.  The patch goes through and changes all implementations
to use signed longs throughout.

Also, x86-64 was using 32-bit quantities for the value passed into local_add()
and local_sub().  Fixed.

All (actually, both) existing users have been audited.

(Also s/__inline__/inline/ in x86_64/local.h)

Cc: Andi Kleen <ak@muc.de>
Cc: Benjamin LaHaise <bcrl@kvack.org>
Cc: Kyle McMartin <kyle@parisc-linux.org>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
include/asm-generic/local.h
include/asm-i386/local.h
include/asm-x86_64/local.h

index de46148..9291c24 100644 (file)
@@ -7,8 +7,15 @@
 #include <asm/atomic.h>
 #include <asm/types.h>
 
-/* An unsigned long type for operations which are atomic for a single
- * CPU.  Usually used in combination with per-cpu variables. */
+/*
+ * A signed long type for operations which are atomic for a single CPU.
+ * Usually used in combination with per-cpu variables.
+ *
+ * This is the default implementation, which uses atomic_long_t.  Which is
+ * rather pointless.  The whole point behind local_t is that some processors
+ * can perform atomic adds and subtracts in a manner which is atomic wrt IRQs
+ * running on this CPU.  local_t allows exploitation of such capabilities.
+ */
 
 /* Implement in terms of atomics. */
 
@@ -20,7 +27,7 @@ typedef struct
 
 #define LOCAL_INIT(i)  { ATOMIC_LONG_INIT(i) }
 
-#define local_read(l)  ((unsigned long)atomic_long_read(&(l)->a))
+#define local_read(l)  atomic_long_read(&(l)->a)
 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
 #define local_inc(l)   atomic_long_inc(&(l)->a)
 #define local_dec(l)   atomic_long_dec(&(l)->a)
index 0177da8..e67fa08 100644 (file)
@@ -5,7 +5,7 @@
 
 typedef struct
 {
-       volatile unsigned long counter;
+       volatile long counter;
 } local_t;
 
 #define LOCAL_INIT(i)  { (i) }
@@ -29,7 +29,7 @@ static __inline__ void local_dec(local_t *v)
                :"m" (v->counter));
 }
 
-static __inline__ void local_add(unsigned long i, local_t *v)
+static __inline__ void local_add(long i, local_t *v)
 {
        __asm__ __volatile__(
                "addl %1,%0"
@@ -37,7 +37,7 @@ static __inline__ void local_add(unsigned long i, local_t *v)
                :"ir" (i), "m" (v->counter));
 }
 
-static __inline__ void local_sub(unsigned long i, local_t *v)
+static __inline__ void local_sub(long i, local_t *v)
 {
        __asm__ __volatile__(
                "subl %1,%0"
index bf14803..cd17945 100644 (file)
@@ -5,7 +5,7 @@
 
 typedef struct
 {
-       volatile unsigned long counter;
+       volatile long counter;
 } local_t;
 
 #define LOCAL_INIT(i)  { (i) }
@@ -13,7 +13,7 @@ typedef struct
 #define local_read(v)  ((v)->counter)
 #define local_set(v,i) (((v)->counter) = (i))
 
-static __inline__ void local_inc(local_t *v)
+static inline void local_inc(local_t *v)
 {
        __asm__ __volatile__(
                "incq %0"
@@ -21,7 +21,7 @@ static __inline__ void local_inc(local_t *v)
                :"m" (v->counter));
 }
 
-static __inline__ void local_dec(local_t *v)
+static inline void local_dec(local_t *v)
 {
        __asm__ __volatile__(
                "decq %0"
@@ -29,7 +29,7 @@ static __inline__ void local_dec(local_t *v)
                :"m" (v->counter));
 }
 
-static __inline__ void local_add(unsigned int i, local_t *v)
+static inline void local_add(long i, local_t *v)
 {
        __asm__ __volatile__(
                "addq %1,%0"
@@ -37,7 +37,7 @@ static __inline__ void local_add(unsigned int i, local_t *v)
                :"ir" (i), "m" (v->counter));
 }
 
-static __inline__ void local_sub(unsigned int i, local_t *v)
+static inline void local_sub(long i, local_t *v)
 {
        __asm__ __volatile__(
                "subq %1,%0"