Date: Wed, 20 Jun 2018 06:46:54 +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-11@freebsd.org Subject: svn commit: r335422 - stable/11/sys/compat/linuxkpi/common/include/asm Message-ID: <201806200646.w5K6ksIP026184@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Wed Jun 20 06:46:54 2018 New Revision: 335422 URL: https://svnweb.freebsd.org/changeset/base/335422 Log: MFC r334712 and r334718: Implement the atomic_dec_if_positive() function in the LinuxKPI. Submitted by: Johannes Lundberg <johalun0@gmail.com> Sponsored by: Mellanox Technologies Sponsored by: Limelight Networks Modified: stable/11/sys/compat/linuxkpi/common/include/asm/atomic.h Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/compat/linuxkpi/common/include/asm/atomic.h ============================================================================== --- stable/11/sys/compat/linuxkpi/common/include/asm/atomic.h Wed Jun 20 06:43:41 2018 (r335421) +++ stable/11/sys/compat/linuxkpi/common/include/asm/atomic.h Wed Jun 20 06:46:54 2018 (r335422) @@ -235,6 +235,23 @@ atomic_cmpxchg(atomic_t *v, int old, int new) __ret.val; \ }) +static inline int +atomic_dec_if_positive(atomic_t *v) +{ + int retval; + int old; + + old = atomic_read(v); + for (;;) { + retval = old - 1; + if (unlikely(retval < 0)) + break; + if (likely(atomic_fcmpset_int(&v->counter, &old, retval))) + break; + } + return (retval); +} + #define LINUX_ATOMIC_OP(op, c_op) \ static inline void atomic_##op(int i, atomic_t *v) \ { \
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201806200646.w5K6ksIP026184>