svn commit: r335422 - stable/11/sys/compat/linuxkpi/common/include/asm

Hans Petter Selasky hselasky at FreeBSD.org
Wed Jun 20 06:46:55 UTC 2018


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 at 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)		\
 {								\


More information about the svn-src-stable-11 mailing list