Commit ebc7bc42 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] Implement atomic_add_negative() on various architectures

Lots of architectures have atomic_add_return() and no atomic_add_negative().

We can implement the latter in terms of the former.
parent b5fc1438
...@@ -115,6 +115,8 @@ static __inline__ long atomic_add_return(int i, atomic_t * v) ...@@ -115,6 +115,8 @@ static __inline__ long atomic_add_return(int i, atomic_t * v)
return result; return result;
} }
#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
static __inline__ long atomic64_add_return(long i, atomic64_t * v) static __inline__ long atomic64_add_return(long i, atomic64_t * v)
{ {
long temp, result; long temp, result;
......
...@@ -56,6 +56,8 @@ extern __inline__ int atomic_add_return(int i, volatile atomic_t *v) ...@@ -56,6 +56,8 @@ extern __inline__ int atomic_add_return(int i, volatile atomic_t *v)
return retval; return retval;
} }
#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
extern __inline__ int atomic_sub_return(int i, volatile atomic_t *v) extern __inline__ int atomic_sub_return(int i, volatile atomic_t *v)
{ {
unsigned long flags; unsigned long flags;
......
...@@ -25,6 +25,7 @@ static __inline__ int atomic_add_return(int i, atomic_t *v) ...@@ -25,6 +25,7 @@ static __inline__ int atomic_add_return(int i, atomic_t *v)
} }
#define atomic_add(i, v) atomic_add_return(i, v) #define atomic_add(i, v) atomic_add_return(i, v)
#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
static __inline__ int atomic_sub_return(int i, atomic_t *v) static __inline__ int atomic_sub_return(int i, atomic_t *v)
{ {
......
...@@ -96,6 +96,8 @@ extern __inline__ int atomic_add_return(int i, atomic_t * v) ...@@ -96,6 +96,8 @@ extern __inline__ int atomic_add_return(int i, atomic_t * v)
return temp; return temp;
} }
#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
extern __inline__ int atomic_sub_return(int i, atomic_t * v) extern __inline__ int atomic_sub_return(int i, atomic_t * v)
{ {
unsigned long temp, flags; unsigned long temp, flags;
......
...@@ -185,6 +185,8 @@ static __inline__ int atomic_read(const atomic_t *v) ...@@ -185,6 +185,8 @@ static __inline__ int atomic_read(const atomic_t *v)
#define atomic_inc_return(v) (__atomic_add_return( 1,(v))) #define atomic_inc_return(v) (__atomic_add_return( 1,(v)))
#define atomic_dec_return(v) (__atomic_add_return( -1,(v))) #define atomic_dec_return(v) (__atomic_add_return( -1,(v)))
#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
#define atomic_dec_and_test(v) (atomic_dec_return(v) == 0) #define atomic_dec_and_test(v) (atomic_dec_return(v) == 0)
#define ATOMIC_INIT(i) { (i) } #define ATOMIC_INIT(i) { (i) }
......
...@@ -54,6 +54,8 @@ static __inline__ int atomic_add_return(int a, atomic_t *v) ...@@ -54,6 +54,8 @@ static __inline__ int atomic_add_return(int a, atomic_t *v)
return t; return t;
} }
#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
static __inline__ void atomic_sub(int a, atomic_t *v) static __inline__ void atomic_sub(int a, atomic_t *v)
{ {
int t; int t;
......
...@@ -53,6 +53,8 @@ static __inline__ int atomic_add_return(int i, atomic_t * v) ...@@ -53,6 +53,8 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
return temp; return temp;
} }
#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
static __inline__ int atomic_sub_return(int i, atomic_t * v) static __inline__ int atomic_sub_return(int i, atomic_t * v)
{ {
unsigned long temp, flags; unsigned long temp, flags;
......
...@@ -33,6 +33,8 @@ extern void atomic_set(atomic_t *, int); ...@@ -33,6 +33,8 @@ extern void atomic_set(atomic_t *, int);
#define atomic_inc_return(v) (__atomic_add_return( 1, (v))) #define atomic_inc_return(v) (__atomic_add_return( 1, (v)))
#define atomic_dec_return(v) (__atomic_add_return( -1, (v))) #define atomic_dec_return(v) (__atomic_add_return( -1, (v)))
#define atomic_add_negative(a, v) (atomic_add_return((a), (v)) < 0)
#define atomic_dec_and_test(v) (atomic_dec_return(v) == 0) #define atomic_dec_and_test(v) (atomic_dec_return(v) == 0)
/* This is the old 24-bit implementation. It's still used internally /* This is the old 24-bit implementation. It's still used internally
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment