From db119089beb7c616722f7e5265a55cecb9c84f12 Mon Sep 17 00:00:00 2001 From: Hans Petter Selasky Date: Mon, 6 Aug 2018 08:40:02 +0000 Subject: Implement atomic_long_cmpxchg() function in the LinuxKPI. Submitted by: Johannes Lundberg MFC after: 1 week Sponsored by: Mellanox Technologies --- sys/compat/linuxkpi/common/include/asm/atomic-long.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'sys/compat/linuxkpi/common') diff --git a/sys/compat/linuxkpi/common/include/asm/atomic-long.h b/sys/compat/linuxkpi/common/include/asm/atomic-long.h index b0763f456b90..b6909e1342e5 100644 --- a/sys/compat/linuxkpi/common/include/asm/atomic-long.h +++ b/sys/compat/linuxkpi/common/include/asm/atomic-long.h @@ -81,6 +81,21 @@ atomic_long_xchg(atomic_long_t *v, long val) return atomic_swap_long(&v->counter, val); } +static inline long +atomic_long_cmpxchg(atomic_long_t *v, long old, long new) +{ + long ret = old; + + for (;;) { + if (atomic_cmpset_long(&v->counter, old, new)) + break; + ret = READ_ONCE(v->counter); + if (ret != old) + break; + } + return (ret); +} + static inline int atomic_long_add_unless(atomic_long_t *v, long a, long u) { -- cgit v1.2.3