Source-Changes-HG archive

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

[src/trunk]: src/common/lib/libc/atomic *** empty log message ***



details:   https://anonhg.NetBSD.org/src/rev/968f6dbdf4e3
branches:  trunk
changeset: 366084:968f6dbdf4e3
user:      skrll <skrll%NetBSD.org@localhost>
date:      Sat May 14 05:35:55 2022 +0000

description:
*** empty log message ***

diffstat:

 common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c |  11 ++++++++---
 common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c |  11 ++++++++---
 common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c  |  11 ++++++++---
 3 files changed, 24 insertions(+), 9 deletions(-)

diffs (87 lines):

diff -r 26c0337f2d08 -r 968f6dbdf4e3 common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c
--- a/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c       Sat May 14 04:04:55 2022 +0000
+++ b/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c       Sat May 14 05:35:55 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atomic_c11_compare_exchange_cas_16.c,v 1.3 2020/09/07 00:52:19 mrg Exp $       */
+/*     $NetBSD: atomic_c11_compare_exchange_cas_16.c,v 1.4 2022/05/14 05:35:55 skrll Exp $     */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -44,12 +44,17 @@
     void *expected, uint16_t desired,
     bool weak, int success, int failure)
 {
-       uint16_t old = *(uint16_t *)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 26c0337f2d08 -r 968f6dbdf4e3 common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c
--- a/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c       Sat May 14 04:04:55 2022 +0000
+++ b/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c       Sat May 14 05:35:55 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atomic_c11_compare_exchange_cas_32.c,v 1.3 2020/09/07 00:52:19 mrg Exp $       */
+/*     $NetBSD: atomic_c11_compare_exchange_cas_32.c,v 1.4 2022/05/14 05:35:55 skrll Exp $     */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -44,12 +44,17 @@
     void *expected, uint32_t desired,
     bool weak, int success, int failure)
 {
-       uint32_t old = *(uint32_t *)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 26c0337f2d08 -r 968f6dbdf4e3 common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c
--- a/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c        Sat May 14 04:04:55 2022 +0000
+++ b/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c        Sat May 14 05:35:55 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atomic_c11_compare_exchange_cas_8.c,v 1.3 2020/09/07 00:52:19 mrg Exp $        */
+/*     $NetBSD: atomic_c11_compare_exchange_cas_8.c,v 1.4 2022/05/14 05:35:55 skrll Exp $      */
 
 /*-
  * Copyright (c) 2007 The NetBSD Foundation, Inc.
@@ -44,12 +44,17 @@
     void *expected, uint8_t desired,
     bool weak, int success, int failure)
 {
-       uint8_t old = *(uint8_t *)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