Date: Mon, 18 May 2020 09:11:41 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r361180 - stable/12/sys/compat/linuxkpi/common/include/asm Message-ID: <202005180911.04I9Bfvs055832@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Mon May 18 09:11:41 2020 New Revision: 361180 URL: https://svnweb.freebsd.org/changeset/base/361180 Log: MFC r360127: Implement the atomic fetch add unless functions for the LinuxKPI. Sponsored by: Mellanox Technologies Modified: stable/12/sys/compat/linuxkpi/common/include/asm/atomic-long.h stable/12/sys/compat/linuxkpi/common/include/asm/atomic.h stable/12/sys/compat/linuxkpi/common/include/asm/atomic64.h Directory Properties: stable/12/ (props changed) Modified: stable/12/sys/compat/linuxkpi/common/include/asm/atomic-long.h ============================================================================== --- stable/12/sys/compat/linuxkpi/common/include/asm/atomic-long.h Mon May 18 09:10:52 2020 (r361179) +++ stable/12/sys/compat/linuxkpi/common/include/asm/atomic-long.h Mon May 18 09:11:41 2020 (r361180) @@ -119,6 +119,20 @@ atomic_long_add_unless(atomic_long_t *v, long a, long } 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) { long i = atomic_long_add(-1, v); Modified: stable/12/sys/compat/linuxkpi/common/include/asm/atomic.h ============================================================================== --- stable/12/sys/compat/linuxkpi/common/include/asm/atomic.h Mon May 18 09:10:52 2020 (r361179) +++ stable/12/sys/compat/linuxkpi/common/include/asm/atomic.h Mon May 18 09:11:41 2020 (r361180) @@ -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) { Modified: stable/12/sys/compat/linuxkpi/common/include/asm/atomic64.h ============================================================================== --- stable/12/sys/compat/linuxkpi/common/include/asm/atomic64.h Mon May 18 09:10:52 2020 (r361179) +++ stable/12/sys/compat/linuxkpi/common/include/asm/atomic64.h Mon May 18 09:11:41 2020 (r361180) @@ -104,6 +104,20 @@ atomic64_add_unless(atomic64_t *v, int64_t a, int64_t } 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) { #if !((defined(__mips__) && !(defined(__mips_n32) || defined(__mips_n64))) || \
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202005180911.04I9Bfvs055832>