Author: hselasky
Date: Mon Apr 20 16:21:37 2020
New Revision: 360127
URL: https://svnweb.freebsd.org/changeset/base/360127

Log:
  Implement the atomic fetch add unless functions for the LinuxKPI.
  
  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   Mon Apr 20 
16:17:16 2020        (r360126)
+++ head/sys/compat/linuxkpi/common/include/asm/atomic-long.h   Mon Apr 20 
16:21:37 2020        (r360127)
@@ -111,6 +111,20 @@ atomic_long_add_unless(atomic_long_t *v, long a, long 
 }
 
 static inline long
+atomic_long_fetch_add_unless(atomic_long_t *v, long a, long u)
+{
+       long c = atomic_long_read(v);
+
+       for (;;) {
+               if (unlikely(c == u))
+                       break;
+               if (likely(atomic_fcmpset_long(&v->counter, &c, c + a)))
+                       break;
+       }
+       return (c);
+}
+
+static inline long
 atomic_long_dec_and_test(atomic_long_t *v)
 {
        long i = atomic_long_add(-1, v);

Modified: head/sys/compat/linuxkpi/common/include/asm/atomic.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/asm/atomic.h        Mon Apr 20 
16:17:16 2020        (r360126)
+++ head/sys/compat/linuxkpi/common/include/asm/atomic.h        Mon Apr 20 
16:21:37 2020        (r360127)
@@ -119,6 +119,20 @@ atomic_add_unless(atomic_t *v, int a, int u)
        return (c != u);
 }
 
+static inline int
+atomic_fetch_add_unless(atomic_t *v, int a, int u)
+{
+       int c = atomic_read(v);
+
+       for (;;) {
+               if (unlikely(c == u))
+                       break;
+               if (likely(atomic_fcmpset_int(&v->counter, &c, c + a)))
+                       break;
+       }
+       return (c);
+}
+
 static inline void
 atomic_clear_mask(unsigned int mask, atomic_t *v)
 {

Modified: head/sys/compat/linuxkpi/common/include/asm/atomic64.h
==============================================================================
--- head/sys/compat/linuxkpi/common/include/asm/atomic64.h      Mon Apr 20 
16:17:16 2020        (r360126)
+++ head/sys/compat/linuxkpi/common/include/asm/atomic64.h      Mon Apr 20 
16:21:37 2020        (r360127)
@@ -104,6 +104,20 @@ atomic64_add_unless(atomic64_t *v, int64_t a, int64_t 
 }
 
 static inline int64_t
+atomic64_fetch_add_unless(atomic64_t *v, int64_t a, int64_t u)
+{
+       int64_t c = atomic64_read(v);
+
+       for (;;) {
+               if (unlikely(c == u))
+                       break;
+               if (likely(atomic_fcmpset_64(&v->counter, &c, c + a)))
+                       break;
+       }
+       return (c);
+}
+
+static inline int64_t
 atomic64_xchg(atomic64_t *v, int64_t i)
 {
 #if !((defined(__mips__) && !(defined(__mips_n32) || defined(__mips_n64))) || \
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to