diff options
| author | skrll <skrll@NetBSD.org> | 2022-05-14 05:35:55 +0000 |
|---|---|---|
| committer | skrll <skrll@NetBSD.org> | 2022-05-14 05:35:55 +0000 |
| commit | 494f3b958bf66d4def4eb7a4aa59be44681fe570 (patch) | |
| tree | 878efe51ba989f7729f51c8f2e7a93ebbb1e9dfd /common | |
| parent | 0f969bb4f861ff5bf1759bca25fe344415d2d465 (diff) | |
*** empty log message ***
Diffstat (limited to 'common')
3 files changed, 24 insertions, 9 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 963daba88f3..96cdb07b487 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.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 @@ __atomic_compare_exchange_2(volatile void *mem, 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 --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 cce3717bcfe..48bdcd0688e 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.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 @@ __atomic_compare_exchange_4(volatile void *mem, 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 --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 3de5431dbf3..10dd49376e3 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.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 @@ __atomic_compare_exchange_1(volatile void *mem, 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; } |
