Implement the atomic fetch add unless functions for the LinuxKPI.
MFC after: 1 week Sponsored by: Mellanox Technologies
This commit is contained in:
parent
f8ae734005
commit
b9bf16adfb
@ -110,6 +110,20 @@ atomic_long_add_unless(atomic_long_t *v, long a, long u)
|
||||
return (c != u);
|
||||
}
|
||||
|
||||
static inline long
|
||||
atomic_long_fetch_add_unless(atomic_long_t *v, long a, long u)
|
||||
{
|
||||
long c = atomic_long_read(v);
|
||||
|
||||
for (;;) {
|
||||
if (unlikely(c == u))
|
||||
break;
|
||||
if (likely(atomic_fcmpset_long(&v->counter, &c, c + a)))
|
||||
break;
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
|
||||
static inline long
|
||||
atomic_long_dec_and_test(atomic_long_t *v)
|
||||
{
|
||||
|
@ -119,6 +119,20 @@ atomic_add_unless(atomic_t *v, int a, int u)
|
||||
return (c != u);
|
||||
}
|
||||
|
||||
static inline int
|
||||
atomic_fetch_add_unless(atomic_t *v, int a, int u)
|
||||
{
|
||||
int c = atomic_read(v);
|
||||
|
||||
for (;;) {
|
||||
if (unlikely(c == u))
|
||||
break;
|
||||
if (likely(atomic_fcmpset_int(&v->counter, &c, c + a)))
|
||||
break;
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
|
||||
static inline void
|
||||
atomic_clear_mask(unsigned int mask, atomic_t *v)
|
||||
{
|
||||
|
@ -103,6 +103,20 @@ atomic64_add_unless(atomic64_t *v, int64_t a, int64_t u)
|
||||
return (c != u);
|
||||
}
|
||||
|
||||
static inline int64_t
|
||||
atomic64_fetch_add_unless(atomic64_t *v, int64_t a, int64_t u)
|
||||
{
|
||||
int64_t c = atomic64_read(v);
|
||||
|
||||
for (;;) {
|
||||
if (unlikely(c == u))
|
||||
break;
|
||||
if (likely(atomic_fcmpset_64(&v->counter, &c, c + a)))
|
||||
break;
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
|
||||
static inline int64_t
|
||||
atomic64_xchg(atomic64_t *v, int64_t i)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user