Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 16 Feb 2017 12:56:10 +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: r313808 - head/sys/compat/linuxkpi/common/include/asm
Message-ID:  <201702161256.v1GCuA3a020713@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: hselasky
Date: Thu Feb 16 12:56:10 2017
New Revision: 313808
URL: https://svnweb.freebsd.org/changeset/base/313808

Log:
  Implement more LinuxKPI atomic functions and macros.
  
  Obtained from:		kmacy @
  MFC after:		1 week
  Sponsored by:		Mellanox Technologies

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

Modified: head/sys/compat/linuxkpi/common/include/asm/atomic-long.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/asm/atomic-long.h	Thu Feb 16 12:20:57 2017	(r313807)
+++ head/sys/compat/linuxkpi/common/include/asm/atomic-long.h	Thu Feb 16 12:56:10 2017	(r313808)
@@ -75,6 +75,12 @@ atomic_long_dec(atomic_long_t *v)
 	return atomic_fetchadd_long(&v->counter, -1) - 1;
 }
 
+static inline long
+atomic_long_xchg(atomic_long_t *v, long val)
+{
+	return atomic_swap_long(&v->counter, val);
+}
+
 static inline int
 atomic_long_add_unless(atomic_long_t *v, long a, long u)
 {

Modified: head/sys/compat/linuxkpi/common/include/asm/atomic.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/asm/atomic.h	Thu Feb 16 12:20:57 2017	(r313807)
+++ head/sys/compat/linuxkpi/common/include/asm/atomic.h	Thu Feb 16 12:56:10 2017	(r313808)
@@ -75,6 +75,12 @@ atomic_set(atomic_t *v, int i)
 }
 
 static inline void
+atomic_set_release(atomic_t *v, int i)
+{
+	atomic_store_rel_int(&v->counter, i);
+}
+
+static inline void
 atomic_set_mask(unsigned int mask, atomic_t *v)
 {
 	atomic_set_int(&v->counter, mask);
@@ -187,8 +193,26 @@ static inline void atomic_##op(int i, at
 		c = old;					\
 }
 
+#define	LINUX_ATOMIC_FETCH_OP(op, c_op)				\
+static inline int atomic_fetch_##op(int i, atomic_t *v)		\
+{								\
+	int c, old;						\
+								\
+	c = v->counter;						\
+	while ((old = atomic_cmpxchg(v, c, c c_op i)) != c)	\
+		c = old;					\
+								\
+	return (c);						\
+}
+
 LINUX_ATOMIC_OP(or, |)
 LINUX_ATOMIC_OP(and, &)
+LINUX_ATOMIC_OP(andnot, &~)
 LINUX_ATOMIC_OP(xor, ^)
 
+LINUX_ATOMIC_FETCH_OP(or, |)
+LINUX_ATOMIC_FETCH_OP(and, &)
+LINUX_ATOMIC_FETCH_OP(andnot, &~)
+LINUX_ATOMIC_FETCH_OP(xor, ^)
+
 #endif					/* _ASM_ATOMIC_H_ */

Modified: head/sys/compat/linuxkpi/common/include/asm/atomic64.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/asm/atomic64.h	Thu Feb 16 12:20:57 2017	(r313807)
+++ head/sys/compat/linuxkpi/common/include/asm/atomic64.h	Thu Feb 16 12:56:10 2017	(r313808)
@@ -36,6 +36,8 @@ typedef struct {
 	volatile int64_t counter;
 } atomic64_t;
 
+#define	ATOMIC64_INIT(x)	{ .counter = (x) }
+
 /*------------------------------------------------------------------------*
  *	64-bit atomic operations
  *------------------------------------------------------------------------*/



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