Author: marcel
Date: Wed Jan  1 22:51:19 2014
New Revision: 260175
URL: http://svnweb.freebsd.org/changeset/base/260175

Log:
  Implement atomic_swap_<type>.
  The operation was documented and implemented partially (both from a
  type and architecture perspective) on 2013-08-21 and got used in
  ZFS with revision 260150 (zfeature.c) and since ZFS is supported on
  ia64, the lack of having atomic_swap became problem.

Modified:
  head/sys/ia64/include/atomic.h

Modified: head/sys/ia64/include/atomic.h
==============================================================================
--- head/sys/ia64/include/atomic.h      Wed Jan  1 22:49:37 2014        
(r260174)
+++ head/sys/ia64/include/atomic.h      Wed Jan  1 22:51:19 2014        
(r260175)
@@ -386,4 +386,32 @@ atomic_fetchadd_long(volatile u_long *p,
        return (value);
 }
 
+/*
+ * <type> atomic_swap_<type>(volatile <type> *p, <type> v);
+ */
+
+static __inline uint32_t
+atomic_swap_32(volatile uint32_t *p, uint32_t v)
+{
+       uint32_t r;
+
+       __asm __volatile ("xchg4 %0 = %3, %2;;" : "=r"(r), "=m"(*p) :
+           "r"(v), "m"(*p) : "memory");
+       return (r);
+}
+
+static __inline uint64_t
+atomic_swap_64(volatile uint64_t *p, uint64_t v)
+{
+       uint64_t r;
+
+       __asm __volatile ("xchg8 %0 = %3, %2;;" : "=r"(r), "=m"(*p) :
+           "r"(v), "m"(*p) : "memory");
+       return (r);
+}
+
+#define        atomic_swap_int         atomic_swap_32
+#define        atomic_swap_long        atomic_swap_64
+#define        atomic_swap_ptr         atomic_swap_64
+
 #endif /* ! _MACHINE_ATOMIC_H_ */
_______________________________________________
svn-src-head@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to