diff options
| author | riastradh <riastradh@NetBSD.org> | 2023-03-30 15:03:35 +0000 |
|---|---|---|
| committer | riastradh <riastradh@NetBSD.org> | 2023-03-30 15:03:35 +0000 |
| commit | 26e084ad405a2d2e1971957cd974a0ef246a594a (patch) | |
| tree | f55c684304ee1959890b7c9adb327e734be0db74 /common | |
| parent | 97e4f81937218b06759d463e95b93063bb2643e4 (diff) | |
libc: Define __atomic_is_lock_free.
Limited to architectures where it is actually needed by gcc for any
calls to stdatomic.h atomic_is_lock_free for now.
We should also add it to other architectures too, along with lockful
atomic r/m/w operations for sizes that can't be handled natively, but
that's a lot more work. It is also necessary for -fno-inline-atomics
but we're missing a lot of other symbols for that too, to be fixed.
For now, this should enable the OpenSSL build to complete on these
architectures again after I reverted a local change.
XXX pullup-10
Diffstat (limited to 'common')
| -rw-r--r-- | common/lib/libc/arch/hppa/atomic/Makefile.inc | 5 | ||||
| -rw-r--r-- | common/lib/libc/arch/m68k/atomic/Makefile.inc | 6 | ||||
| -rw-r--r-- | common/lib/libc/arch/mips/atomic/Makefile.inc | 5 | ||||
| -rw-r--r-- | common/lib/libc/arch/sh3/atomic/Makefile.inc | 5 | ||||
| -rw-r--r-- | common/lib/libc/arch/sparc/atomic/Makefile.inc | 5 | ||||
| -rw-r--r-- | common/lib/libc/arch/vax/atomic/Makefile.inc | 5 | ||||
| -rw-r--r-- | common/lib/libc/atomic/atomic_is_lock_free.c | 54 |
7 files changed, 75 insertions, 10 deletions
diff --git a/common/lib/libc/arch/hppa/atomic/Makefile.inc b/common/lib/libc/arch/hppa/atomic/Makefile.inc index 3981fb778c4..bcce659ce82 100644 --- a/common/lib/libc/arch/hppa/atomic/Makefile.inc +++ b/common/lib/libc/arch/hppa/atomic/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.14 2019/02/28 02:35:37 isaki Exp $ +# $NetBSD: Makefile.inc,v 1.15 2023/03/30 15:03:35 riastradh Exp $ .if defined(LIB) @@ -36,6 +36,7 @@ SRCS+= atomic_xor_32_cas.c atomic_xor_16_cas.c atomic_xor_8_cas.c \ atomic_cas_32_cas.c atomic_cas_16_cas.c atomic_cas_8_cas.c \ atomic_c11_compare_exchange_cas_32.c \ atomic_c11_compare_exchange_cas_16.c \ - atomic_c11_compare_exchange_cas_8.c + atomic_c11_compare_exchange_cas_8.c \ + atomic_is_lock_free.c .endif .endif diff --git a/common/lib/libc/arch/m68k/atomic/Makefile.inc b/common/lib/libc/arch/m68k/atomic/Makefile.inc index 2919ea62fff..4e2f9097733 100644 --- a/common/lib/libc/arch/m68k/atomic/Makefile.inc +++ b/common/lib/libc/arch/m68k/atomic/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.15 2019/02/28 02:35:37 isaki Exp $ +# $NetBSD: Makefile.inc,v 1.16 2023/03/30 15:03:35 riastradh Exp $ # # Note: The atomic operations here in these assembly files are atomic @@ -57,3 +57,7 @@ CPPFLAGS+= -D__HAVE_ASM_ATOMIC_CAS_UP -D__HAVE_ASM_ATOMIC_CAS_16_UP \ .endif .endif + +.if defined(LIB) && ${LIB} == "c" +SRCS+= atomic_is_lock_free.c +.endif diff --git a/common/lib/libc/arch/mips/atomic/Makefile.inc b/common/lib/libc/arch/mips/atomic/Makefile.inc index 23ecf6c8a03..cd4888ce233 100644 --- a/common/lib/libc/arch/mips/atomic/Makefile.inc +++ b/common/lib/libc/arch/mips/atomic/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.15 2021/04/25 22:45:16 christos Exp $ +# $NetBSD: Makefile.inc,v 1.16 2023/03/30 15:03:36 riastradh Exp $ .if defined(LIB) && (${LIB} == "kern" || ${LIB} == "c" || ${LIB} == "pthread" \ || ${LIB} == "rump") @@ -51,6 +51,9 @@ SRCS+= atomic_xor_32_cas.c atomic_xor_16_cas.c atomic_xor_8_cas.c \ atomic_c11_compare_exchange_cas_32.c \ atomic_c11_compare_exchange_cas_16.c \ atomic_c11_compare_exchange_cas_8.c +.if !${MACHINE_MIPS64} +SRCS+= atomic_is_lock_free.c +.endif .endif .if defined(LIB) && (${LIB} == "kern" || ${LIB} == "rump") diff --git a/common/lib/libc/arch/sh3/atomic/Makefile.inc b/common/lib/libc/arch/sh3/atomic/Makefile.inc index f4baebd11c9..1e5b8eb0d09 100644 --- a/common/lib/libc/arch/sh3/atomic/Makefile.inc +++ b/common/lib/libc/arch/sh3/atomic/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.8 2019/02/28 02:35:37 isaki Exp $ +# $NetBSD: Makefile.inc,v 1.9 2023/03/30 15:03:36 riastradh Exp $ .if defined(LIB) && (${LIB} == "kern" || ${LIB} == "c" || ${LIB} == "pthread" \ || ${LIB} == "rump") @@ -20,7 +20,8 @@ SRCS+= atomic_add_16_cas.c atomic_add_8_cas.c \ atomic_cas_32_cas.c atomic_cas_16_cas.c atomic_cas_8_cas.c \ atomic_c11_compare_exchange_cas_32.c \ atomic_c11_compare_exchange_cas_16.c \ - atomic_c11_compare_exchange_cas_8.c + atomic_c11_compare_exchange_cas_8.c \ + atomic_is_lock_free.c .endif .endif diff --git a/common/lib/libc/arch/sparc/atomic/Makefile.inc b/common/lib/libc/arch/sparc/atomic/Makefile.inc index 31a2435d08f..2fd49fc336c 100644 --- a/common/lib/libc/arch/sparc/atomic/Makefile.inc +++ b/common/lib/libc/arch/sparc/atomic/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.23 2019/02/28 02:35:37 isaki Exp $ +# $NetBSD: Makefile.inc,v 1.24 2023/03/30 15:03:36 riastradh Exp $ .include <bsd.own.mk> @@ -46,7 +46,8 @@ SRCS+= atomic_nand_16_cas.c atomic_nand_8_cas.c \ atomic_c11_compare_exchange_cas_32.c \ atomic_c11_compare_exchange_cas_16.c \ atomic_c11_compare_exchange_cas_8.c \ - atomic_load.c atomic_store.c + atomic_load.c atomic_store.c \ + atomic_is_lock_free.c . endif . if (${LIB} == "kern" || ${LIB} == "rump") diff --git a/common/lib/libc/arch/vax/atomic/Makefile.inc b/common/lib/libc/arch/vax/atomic/Makefile.inc index 7cb9853844c..2bc822b88d8 100644 --- a/common/lib/libc/arch/vax/atomic/Makefile.inc +++ b/common/lib/libc/arch/vax/atomic/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.8 2019/02/28 02:35:38 isaki Exp $ +# $NetBSD: Makefile.inc,v 1.9 2023/03/30 15:03:36 riastradh Exp $ .if defined(LIB) && (${LIB} == "kern" || ${LIB} == "c" || ${LIB} == "pthread" \ || ${LIB} == "rump") @@ -20,7 +20,8 @@ SRCS+= atomic_add_16_cas.c atomic_add_8_cas.c \ atomic_swap_16_cas.c atomic_swap_8_cas.c \ atomic_c11_compare_exchange_cas_32.c \ atomic_c11_compare_exchange_cas_16.c \ - atomic_c11_compare_exchange_cas_8.c + atomic_c11_compare_exchange_cas_8.c \ + atomic_is_lock_free.c .endif .endif diff --git a/common/lib/libc/atomic/atomic_is_lock_free.c b/common/lib/libc/atomic/atomic_is_lock_free.c new file mode 100644 index 00000000000..dae40ca9964 --- /dev/null +++ b/common/lib/libc/atomic/atomic_is_lock_free.c @@ -0,0 +1,54 @@ +/* $NetBSD: atomic_is_lock_free.c,v 1.1 2023/03/30 15:03:36 riastradh Exp $ */ + +/*- + * Copyright (c) 2023 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include <sys/cdefs.h> +__RCSID("$NetBSD: atomic_is_lock_free.c,v 1.1 2023/03/30 15:03:36 riastradh Exp $"); + +#include <sys/types.h> + +#include <sys/stdbool.h> + +bool +__atomic_is_lock_free(size_t n, const volatile void *p __unused) +{ + + switch (n) { + case 1: + return __atomic_always_lock_free(1, 0); + case 2: + return __atomic_always_lock_free(2, 0); + case 4: + return __atomic_always_lock_free(4, 0); + case 8: + return __atomic_always_lock_free(8, 0); + case 16: + return __atomic_always_lock_free(16, 0); + default: + return false; + } +} |
