Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-9]: src/common/lib/libc/atomic Pull up following revision(s) (req...



details:   https://anonhg.NetBSD.org/src/rev/7b3955ecd904
branches:  netbsd-9
changeset: 366126:7b3955ecd904
user:      martin <martin%NetBSD.org@localhost>
date:      Sun May 15 12:37:00 2022 +0000

description:
Pull up following revision(s) (requested by skrll in ticket #1451):

        common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c: revision 1.4
        common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c: revision 1.4
        common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c: revision 1.4

PR 56832:
fix C implementations of __atomic_compare_exchange*

diffstat:

 common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c |  17 ++++++++----
 common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c |  17 ++++++++----
 common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c  |  17 ++++++++----
 3 files changed, 33 insertions(+), 18 deletions(-)

diffs (120 lines):

diff -r 7970d4c9f354 -r 7b3955ecd904 common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c
--- a/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c       Sun May 15 12:29:46 2022 +0000
+++ b/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c       Sun May 15 12:37:00 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atomic_c11_compare_exchange_cas_16.c,v 1.2 2014/11/04 19:56:44 joerg Exp $     */
+/*     $NetBSD: atomic_c11_compare_exchange_cas_16.c,v 1.2.20.1 2022/05/15 12:37:00 martin Exp $       */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -36,20 +36,25 @@
 #endif
 #include <sys/atomic.h>
 
-bool __atomic_compare_exchange_2(volatile uint16_t *, uint16_t *, uint16_t,
+bool __atomic_compare_exchange_2(volatile void *, void *, uint16_t,
     bool, int, int);
 
 bool
-__atomic_compare_exchange_2(volatile uint16_t *mem,
-    uint16_t *expected, uint16_t desired,
+__atomic_compare_exchange_2(volatile void *mem,
+    void *expected, uint16_t desired,
     bool weak, int success, int failure)
 {
-       uint16_t old = *expected;
+       uint16_t * const ep = expected;
+       const uint16_t old = *ep;
 
        /*
         * Ignore the details (weak, memory model on success and failure)
         * and just do the cas. If we get here the compiler couldn't
         * do better and it mostly will not matter at all.
         */
-       return atomic_cas_16(mem, old, desired) == old;
+       const uint16_t prev = atomic_cas_16(mem, old, desired);
+       if (prev == old)
+               return true;
+       *ep = prev;
+       return false;
 }
diff -r 7970d4c9f354 -r 7b3955ecd904 common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c
--- a/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c       Sun May 15 12:29:46 2022 +0000
+++ b/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c       Sun May 15 12:37:00 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atomic_c11_compare_exchange_cas_32.c,v 1.2 2014/11/04 19:56:44 joerg Exp $     */
+/*     $NetBSD: atomic_c11_compare_exchange_cas_32.c,v 1.2.20.1 2022/05/15 12:37:00 martin Exp $       */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -36,20 +36,25 @@
 #endif
 #include <sys/atomic.h>
 
-bool __atomic_compare_exchange_4(volatile uint32_t *, uint32_t *, uint32_t,
+bool __atomic_compare_exchange_4(volatile void *, void *, uint32_t,
     bool, int, int);
 
 bool
-__atomic_compare_exchange_4(volatile uint32_t *mem,
-    uint32_t *expected, uint32_t desired,
+__atomic_compare_exchange_4(volatile void *mem,
+    void *expected, uint32_t desired,
     bool weak, int success, int failure)
 {
-       uint32_t old = *expected;
+       uint32_t * const ep = expected;
+       const uint32_t old = *ep;
 
        /*
         * Ignore the details (weak, memory model on success and failure)
         * and just do the cas. If we get here the compiler couldn't
         * do better and it mostly will not matter at all.
         */
-       return atomic_cas_32(mem, old, desired) == old;
+       const uint32_t prev = atomic_cas_8(mem, old, desired);
+       if (prev == old)
+               return true;
+       *ep = prev;
+       return false;
 }
diff -r 7970d4c9f354 -r 7b3955ecd904 common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c
--- a/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c        Sun May 15 12:29:46 2022 +0000
+++ b/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c        Sun May 15 12:37:00 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atomic_c11_compare_exchange_cas_8.c,v 1.2 2014/11/04 19:56:44 joerg Exp $      */
+/*     $NetBSD: atomic_c11_compare_exchange_cas_8.c,v 1.2.20.1 2022/05/15 12:37:00 martin Exp $        */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -36,20 +36,25 @@
 #endif
 #include <sys/atomic.h>
 
-bool __atomic_compare_exchange_1(volatile uint8_t *, uint8_t *, uint8_t,
+bool __atomic_compare_exchange_1(volatile void *, void *, uint8_t,
     bool, int, int);
 
 bool
-__atomic_compare_exchange_1(volatile uint8_t *mem,
-    uint8_t *expected, uint8_t desired,
+__atomic_compare_exchange_1(volatile void *mem,
+    void *expected, uint8_t desired,
     bool weak, int success, int failure)
 {
-       uint8_t old = *expected;
+       uint8_t * const ep = expected;
+       const uint8_t old = *ep;
 
        /*
         * Ignore the details (weak, memory model on success and failure)
         * and just do the cas. If we get here the compiler couldn't
         * do better and it mostly will not matter at all.
         */
-       return atomic_cas_8(mem, old, desired) == old;
+       const uint8_t prev = atomic_cas_8(mem, old, desired);
+       if (prev == old)
+               return true;
+       *ep = prev;
+       return false;
 }



Home | Main Index | Thread Index | Old Index