Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 23 May 2016 16:19: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: r300517 - head/sys/compat/linuxkpi/common/include/asm
Message-ID:  <201605231619.u4NGJpki088309@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Mon May 23 16:19:51 2016
New Revision: 300517
URL: https://svnweb.freebsd.org/changeset/base/300517

Log:
  Implement "atomic_long_add_unless()" in the LinuxKPI and fix the
  implementation of "atomic_long_inc_not_zero()".
  
  Found by:	ngie @
  MFC after:	1 week
  Sponsored by:	Mellanox Technologies

Modified:
  head/sys/compat/linuxkpi/common/include/asm/atomic-long.h

Modified: head/sys/compat/linuxkpi/common/include/asm/atomic-long.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/asm/atomic-long.h	Mon May 23 16:12:11 2016	(r300516)
+++ head/sys/compat/linuxkpi/common/include/asm/atomic-long.h	Mon May 23 16:19:51 2016	(r300517)
@@ -41,7 +41,7 @@ typedef struct {
 
 #define	atomic_long_add(i, v)		atomic_long_add_return((i), (v))
 #define	atomic_long_inc_return(v)	atomic_long_add_return(1, (v))
-#define	atomic_long_inc_not_zero(v)	atomic_long_inc_not_zero(v)
+#define	atomic_long_inc_not_zero(v)	atomic_long_add_unless((v), 1, 0)
 
 static inline long
 atomic_long_add_return(long i, atomic_long_t *v)
@@ -73,6 +73,21 @@ atomic_long_dec(atomic_long_t *v)
 	return atomic_fetchadd_long(&v->counter, -1) - 1;
 }
 
+static inline int
+atomic_long_add_unless(atomic_long_t *v, long a, long u)
+{
+	long c;
+
+	for (;;) {
+		c = atomic_long_read(v);
+		if (unlikely(c == u))
+			break;
+		if (likely(atomic_cmpset_long(&v->counter, c, c + a)))
+			break;
+	}
+	return (c != u);
+}
+
 static inline long
 atomic_long_dec_and_test(atomic_long_t *v)
 {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605231619.u4NGJpki088309>