Implement the atomic fetch add unless functions for the LinuxKPI.

MFC after:	1 week
Sponsored by:	Mellanox Technologies
This commit is contained in:
Hans Petter Selasky 2020-04-20 16:21:37 +00:00
parent f8ae734005
commit b9bf16adfb
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=360127
3 changed files with 42 additions and 0 deletions

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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)
{