summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authormartin <martin@NetBSD.org>2022-05-15 12:37:00 +0000
committermartin <martin@NetBSD.org>2022-05-15 12:37:00 +0000
commit010faf825ac26df299e5fcbcf67674b1e57d0fe1 (patch)
treec4ca9a1b33ba622d3b427a13cd892b897b81ad69 /common
parent6fc41504c50d50342c042851fe220655ac779be5 (diff)
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 (limited to 'common')
-rw-r--r--common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c17
-rw-r--r--common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c17
-rw-r--r--common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c17
3 files changed, 33 insertions, 18 deletions
diff --git a/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c b/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c
index f626a78d9b1..05430d1af84 100644
--- a/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c
+++ b/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c
@@ -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 --git a/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c b/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c
index e7b72039c4e..d1cd874bc7b 100644
--- a/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c
+++ b/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c
@@ -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 --git a/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c b/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c
index 3126bcc8794..bec0a97e329 100644
--- a/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c
+++ b/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c
@@ -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;
}