Module Name: src Committed By: martin Date: Sun May 15 12:37:00 UTC 2022
Modified Files: src/common/lib/libc/atomic [netbsd-9]: atomic_c11_compare_exchange_cas_16.c atomic_c11_compare_exchange_cas_32.c atomic_c11_compare_exchange_cas_8.c Log Message: 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* To generate a diff of this commit: cvs rdiff -u -r1.2 -r1.2.20.1 \ src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c \ src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c \ src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c diff -u src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c:1.2 src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c:1.2.20.1 --- src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c:1.2 Tue Nov 4 19:56:44 2014 +++ src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_16.c Sun May 15 12:37:00 2022 @@ -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; } Index: src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c diff -u src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c:1.2 src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c:1.2.20.1 --- src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c:1.2 Tue Nov 4 19:56:44 2014 +++ src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_32.c Sun May 15 12:37:00 2022 @@ -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; } Index: src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c diff -u src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c:1.2 src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c:1.2.20.1 --- src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c:1.2 Tue Nov 4 19:56:44 2014 +++ src/common/lib/libc/atomic/atomic_c11_compare_exchange_cas_8.c Sun May 15 12:37:00 2022 @@ -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; }