[S390] atomic: implement atomic64_dec_if_positive
Implement atomic64_dec_if_positive and add missing system.h header include. Signed-off-by: Heiko Carstens <heiko.carstens@de.ibm.com> Signed-off-by: Martin Schwidefsky <schwidefsky@de.ibm.com>
This commit is contained in:
committed by
Martin Schwidefsky
parent
1ef6acf597
commit
2ddb3ec414
@@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
#include <linux/compiler.h>
|
#include <linux/compiler.h>
|
||||||
#include <linux/types.h>
|
#include <linux/types.h>
|
||||||
|
#include <asm/system.h>
|
||||||
|
|
||||||
#define ATOMIC_INIT(i) { (i) }
|
#define ATOMIC_INIT(i) { (i) }
|
||||||
|
|
||||||
@@ -274,6 +275,7 @@ static inline void atomic64_clear_mask(unsigned long long mask, atomic64_t *v)
|
|||||||
static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
|
static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
|
||||||
{
|
{
|
||||||
long long c, old;
|
long long c, old;
|
||||||
|
|
||||||
c = atomic64_read(v);
|
c = atomic64_read(v);
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (unlikely(c == u))
|
if (unlikely(c == u))
|
||||||
@@ -286,6 +288,23 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
|
|||||||
return c != u;
|
return c != u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline long long atomic64_dec_if_positive(atomic64_t *v)
|
||||||
|
{
|
||||||
|
long long c, old, dec;
|
||||||
|
|
||||||
|
c = atomic64_read(v);
|
||||||
|
for (;;) {
|
||||||
|
dec = c - 1;
|
||||||
|
if (unlikely(dec < 0))
|
||||||
|
break;
|
||||||
|
old = atomic64_cmpxchg((v), c, dec);
|
||||||
|
if (likely(old == c))
|
||||||
|
break;
|
||||||
|
c = old;
|
||||||
|
}
|
||||||
|
return dec;
|
||||||
|
}
|
||||||
|
|
||||||
#define atomic64_add(_i, _v) atomic64_add_return(_i, _v)
|
#define atomic64_add(_i, _v) atomic64_add_return(_i, _v)
|
||||||
#define atomic64_add_negative(_i, _v) (atomic64_add_return(_i, _v) < 0)
|
#define atomic64_add_negative(_i, _v) (atomic64_add_return(_i, _v) < 0)
|
||||||
#define atomic64_inc(_v) atomic64_add_return(1, _v)
|
#define atomic64_inc(_v) atomic64_add_return(1, _v)
|
||||||
|
Reference in New Issue
Block a user