Date: Wed, 6 Jun 2018 13:59:51 +0000 (UTC) From: Hans Petter Selasky <hselasky@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334712 - head/sys/compat/linuxkpi/common/include/asm Message-ID: <201806061359.w56DxpSZ020224@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: hselasky Date: Wed Jun 6 13:59:51 2018 New Revision: 334712 URL: https://svnweb.freebsd.org/changeset/base/334712 Log: Implement the atomic_dec_if_positive() function in the LinuxKPI. Submitted by: Johannes Lundberg <johalun0@gmail.com> MFC after: 1 week Sponsored by: Mellanox Technologies Sponsored by: Limelight Networks Modified: head/sys/compat/linuxkpi/common/include/asm/atomic.h Modified: head/sys/compat/linuxkpi/common/include/asm/atomic.h ============================================================================== --- head/sys/compat/linuxkpi/common/include/asm/atomic.h Wed Jun 6 13:37:31 2018 (r334711) +++ head/sys/compat/linuxkpi/common/include/asm/atomic.h Wed Jun 6 13:59:51 2018 (r334712) @@ -235,6 +235,22 @@ atomic_cmpxchg(atomic_t *v, int old, int new) __ret.val; \ }) +static inline int +atomic_dec_if_positive(atomic_t *v) +{ + int retval; + int curr; + + do { + curr = atomic_read(v); + retval = curr - 1; + if (unlikely(retval < 0)) + break; + } while (!likely(atomic_cmpset_int(&v->counter, curr, retval))); + + 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?201806061359.w56DxpSZ020224>