diff options
author | hselasky <hselasky@FreeBSD.org> | 2016-05-23 16:19:51 +0000 |
---|---|---|
committer | hselasky <hselasky@FreeBSD.org> | 2016-05-23 16:19:51 +0000 |
commit | 2404d6db8a6db4d252d6434b06430b2d19e946f7 (patch) | |
tree | 2daec413d48f12ec4eed7a679227500c095fbe71 | |
parent | 4f8526f5810bbe1bda8a739da91640d5bfa09296 (diff) | |
download | FreeBSD-src-2404d6db8a6db4d252d6434b06430b2d19e946f7.zip FreeBSD-src-2404d6db8a6db4d252d6434b06430b2d19e946f7.tar.gz |
Implement "atomic_long_add_unless()" in the LinuxKPI and fix the
implementation of "atomic_long_inc_not_zero()".
Found by: ngie @
MFC after: 1 week
Sponsored by: Mellanox Technologies
-rw-r--r-- | sys/compat/linuxkpi/common/include/asm/atomic-long.h | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/sys/compat/linuxkpi/common/include/asm/atomic-long.h b/sys/compat/linuxkpi/common/include/asm/atomic-long.h index 90187fc..6fbdc5e 100644 --- a/sys/compat/linuxkpi/common/include/asm/atomic-long.h +++ b/sys/compat/linuxkpi/common/include/asm/atomic-long.h @@ -41,7 +41,7 @@ typedef struct { #define atomic_long_add(i, v) atomic_long_add_return((i), (v)) #define atomic_long_inc_return(v) atomic_long_add_return(1, (v)) -#define atomic_long_inc_not_zero(v) atomic_long_inc_not_zero(v) +#define atomic_long_inc_not_zero(v) atomic_long_add_unless((v), 1, 0) static inline long atomic_long_add_return(long i, atomic_long_t *v) @@ -73,6 +73,21 @@ atomic_long_dec(atomic_long_t *v) return atomic_fetchadd_long(&v->counter, -1) - 1; } +static inline int +atomic_long_add_unless(atomic_long_t *v, long a, long u) +{ + long c; + + for (;;) { + c = atomic_long_read(v); + if (unlikely(c == u)) + break; + if (likely(atomic_cmpset_long(&v->counter, c, c + a))) + break; + } + return (c != u); +} + static inline long atomic_long_dec_and_test(atomic_long_t *v) { |