diff options
Diffstat (limited to 'sys/ofed/include/asm/atomic.h')
-rw-r--r-- | sys/ofed/include/asm/atomic.h | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/sys/ofed/include/asm/atomic.h b/sys/ofed/include/asm/atomic.h index 5c5caa0..46e0370 100644 --- a/sys/ofed/include/asm/atomic.h +++ b/sys/ofed/include/asm/atomic.h @@ -45,6 +45,7 @@ typedef struct { #define atomic_sub_and_test(i, v) (atomic_sub_return((i), (v)) == 0) #define atomic_dec_and_test(v) (atomic_sub_return(1, (v)) == 0) #define atomic_inc_and_test(v) (atomic_add_return(1, (v)) == 0) +#define atomic_dec_return(v) atomic_sub_return(1, (v)) static inline int atomic_add_return(int i, atomic_t *v) @@ -82,4 +83,25 @@ atomic_dec(atomic_t *v) return atomic_fetchadd_int(&v->counter, -1) - 1; } +static inline int atomic_add_unless(atomic_t *v, int a, int u) +{ + int c, old; + c = atomic_read(v); + for (;;) { + if (unlikely(c == (u))) + break; + // old = atomic_cmpxchg((v), c, c + (a)); /*Linux*/ + old = atomic_cmpset_int(&v->counter, c, c + (a)); + if (likely(old == c)) + break; + c = old; + } + return c != (u); +} + +#define atomic_inc_not_zero(v) atomic_add_unless((v), 1, 0) + + + + #endif /* _ASM_ATOMIC_H_ */ |