Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 24 Oct 2019 15:46:00 +0000 (UTC)
From:      Andriy Gapon <avg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org
Subject:   svn commit: r354027 - in stable/12/sys: arm/include mips/include powerpc/include
Message-ID:  <201910241546.x9OFk0jZ056319@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: avg
Date: Thu Oct 24 15:46:00 2019
New Revision: 354027
URL: https://svnweb.freebsd.org/changeset/base/354027

Log:
  MFC r341787 by hselasky: Implement atomic_swap_xxx() for all platforms.

Modified:
  stable/12/sys/arm/include/atomic.h
  stable/12/sys/mips/include/atomic.h
  stable/12/sys/powerpc/include/atomic.h
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/arm/include/atomic.h
==============================================================================
--- stable/12/sys/arm/include/atomic.h	Thu Oct 24 15:04:52 2019	(r354026)
+++ stable/12/sys/arm/include/atomic.h	Thu Oct 24 15:46:00 2019	(r354027)
@@ -55,6 +55,13 @@
 #include <machine/atomic-v4.h>
 #endif /* Arch >= v6 */
 
+static __inline u_long
+atomic_swap_long(volatile u_long *p, u_long v)
+{
+
+	return (atomic_swap_32((volatile uint32_t *)p, v));
+}
+
 #define atomic_clear_ptr		atomic_clear_32
 #define atomic_clear_acq_ptr		atomic_clear_acq_32
 #define atomic_clear_rel_ptr		atomic_clear_rel_32

Modified: stable/12/sys/mips/include/atomic.h
==============================================================================
--- stable/12/sys/mips/include/atomic.h	Thu Oct 24 15:04:52 2019	(r354026)
+++ stable/12/sys/mips/include/atomic.h	Thu Oct 24 15:46:00 2019	(r354027)
@@ -759,4 +759,68 @@ atomic_thread_fence_seq_cst(void)
 #define	atomic_store_rel_ptr	atomic_store_rel_long
 #define	atomic_readandclear_ptr	atomic_readandclear_long
 
+static __inline unsigned int
+atomic_swap_int(volatile unsigned int *ptr, const unsigned int value)
+{
+	unsigned int retval;
+
+	retval = *ptr;
+
+	while (!atomic_fcmpset_int(ptr, &retval, value))
+		;
+	return (retval);
+}
+
+static __inline uint32_t
+atomic_swap_32(volatile uint32_t *ptr, const uint32_t value)
+{
+	uint32_t retval;
+
+	retval = *ptr;
+
+	while (!atomic_fcmpset_32(ptr, &retval, value))
+		;
+	return (retval);
+}
+
+#if defined(__mips_n64) || defined(__mips_n32)
+static __inline uint64_t
+atomic_swap_64(volatile uint64_t *ptr, const uint64_t value)
+{
+	uint64_t retval;
+
+	retval = *ptr;
+
+	while (!atomic_fcmpset_64(ptr, &retval, value))
+		;
+	return (retval);
+}
+#endif
+
+static __inline unsigned long
+atomic_swap_long(volatile unsigned long *ptr, const unsigned long value)
+{
+	unsigned long retval;
+
+	retval = *ptr;
+
+	while (!atomic_fcmpset_32((volatile uint32_t *)ptr,
+	    (uint32_t *)&retval, value))
+		;
+	return (retval);
+}
+
+static __inline uintptr_t
+atomic_swap_ptr(volatile uintptr_t *ptr, const uintptr_t value)
+{
+	uintptr_t retval;
+
+	retval = *ptr;
+
+	while (!atomic_fcmpset_32((volatile uint32_t *)ptr,
+	    (uint32_t *)&retval, value))
+		;
+	return (retval);
+}
+
 #endif /* ! _MACHINE_ATOMIC_H_ */

Modified: stable/12/sys/powerpc/include/atomic.h
==============================================================================
--- stable/12/sys/powerpc/include/atomic.h	Thu Oct 24 15:04:52 2019	(r354026)
+++ stable/12/sys/powerpc/include/atomic.h	Thu Oct 24 15:46:00 2019	(r354027)
@@ -852,6 +852,9 @@ atomic_swap_64(volatile u_long *p, u_long v)
 #define	atomic_fetchadd_64	atomic_fetchadd_long
 #define	atomic_swap_long	atomic_swap_64
 #define	atomic_swap_ptr		atomic_swap_64
+#else
+#define	atomic_swap_long(p,v)	atomic_swap_32((volatile u_int *)(p), v)
+#define	atomic_swap_ptr(p,v)	atomic_swap_32((volatile u_int *)(p), v)
 #endif
 
 #undef __ATOMIC_REL



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