Module Name:    src
Committed By:   riastradh
Date:           Thu Mar 30 15:03:36 UTC 2023

Modified Files:
        src/common/lib/libc/arch/hppa/atomic: Makefile.inc
        src/common/lib/libc/arch/m68k/atomic: Makefile.inc
        src/common/lib/libc/arch/mips/atomic: Makefile.inc
        src/common/lib/libc/arch/sh3/atomic: Makefile.inc
        src/common/lib/libc/arch/sparc/atomic: Makefile.inc
        src/common/lib/libc/arch/vax/atomic: Makefile.inc
Added Files:
        src/common/lib/libc/atomic: atomic_is_lock_free.c

Log Message:
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


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/common/lib/libc/arch/hppa/atomic/Makefile.inc
cvs rdiff -u -r1.15 -r1.16 src/common/lib/libc/arch/m68k/atomic/Makefile.inc
cvs rdiff -u -r1.15 -r1.16 src/common/lib/libc/arch/mips/atomic/Makefile.inc
cvs rdiff -u -r1.8 -r1.9 src/common/lib/libc/arch/sh3/atomic/Makefile.inc
cvs rdiff -u -r1.23 -r1.24 src/common/lib/libc/arch/sparc/atomic/Makefile.inc
cvs rdiff -u -r1.8 -r1.9 src/common/lib/libc/arch/vax/atomic/Makefile.inc
cvs rdiff -u -r0 -r1.1 src/common/lib/libc/atomic/atomic_is_lock_free.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/arch/hppa/atomic/Makefile.inc
diff -u src/common/lib/libc/arch/hppa/atomic/Makefile.inc:1.14 src/common/lib/libc/arch/hppa/atomic/Makefile.inc:1.15
--- src/common/lib/libc/arch/hppa/atomic/Makefile.inc:1.14	Thu Feb 28 02:35:37 2019
+++ src/common/lib/libc/arch/hppa/atomic/Makefile.inc	Thu Mar 30 15:03:35 2023
@@ -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
 	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

Index: src/common/lib/libc/arch/m68k/atomic/Makefile.inc
diff -u src/common/lib/libc/arch/m68k/atomic/Makefile.inc:1.15 src/common/lib/libc/arch/m68k/atomic/Makefile.inc:1.16
--- src/common/lib/libc/arch/m68k/atomic/Makefile.inc:1.15	Thu Feb 28 02:35:37 2019
+++ src/common/lib/libc/arch/m68k/atomic/Makefile.inc	Thu Mar 30 15:03:35 2023
@@ -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
 
 .endif
 .endif
+
+.if defined(LIB) && ${LIB} == "c"
+SRCS+=	atomic_is_lock_free.c
+.endif

Index: src/common/lib/libc/arch/mips/atomic/Makefile.inc
diff -u src/common/lib/libc/arch/mips/atomic/Makefile.inc:1.15 src/common/lib/libc/arch/mips/atomic/Makefile.inc:1.16
--- src/common/lib/libc/arch/mips/atomic/Makefile.inc:1.15	Sun Apr 25 22:45:16 2021
+++ src/common/lib/libc/arch/mips/atomic/Makefile.inc	Thu Mar 30 15:03:36 2023
@@ -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
 	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")

Index: src/common/lib/libc/arch/sh3/atomic/Makefile.inc
diff -u src/common/lib/libc/arch/sh3/atomic/Makefile.inc:1.8 src/common/lib/libc/arch/sh3/atomic/Makefile.inc:1.9
--- src/common/lib/libc/arch/sh3/atomic/Makefile.inc:1.8	Thu Feb 28 02:35:37 2019
+++ src/common/lib/libc/arch/sh3/atomic/Makefile.inc	Thu Mar 30 15:03:36 2023
@@ -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_
 	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

Index: src/common/lib/libc/arch/sparc/atomic/Makefile.inc
diff -u src/common/lib/libc/arch/sparc/atomic/Makefile.inc:1.23 src/common/lib/libc/arch/sparc/atomic/Makefile.inc:1.24
--- src/common/lib/libc/arch/sparc/atomic/Makefile.inc:1.23	Thu Feb 28 02:35:37 2019
+++ src/common/lib/libc/arch/sparc/atomic/Makefile.inc	Thu Mar 30 15:03:36 2023
@@ -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_
 	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")

Index: src/common/lib/libc/arch/vax/atomic/Makefile.inc
diff -u src/common/lib/libc/arch/vax/atomic/Makefile.inc:1.8 src/common/lib/libc/arch/vax/atomic/Makefile.inc:1.9
--- src/common/lib/libc/arch/vax/atomic/Makefile.inc:1.8	Thu Feb 28 02:35:38 2019
+++ src/common/lib/libc/arch/vax/atomic/Makefile.inc	Thu Mar 30 15:03:36 2023
@@ -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_
 	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

Added files:

Index: src/common/lib/libc/atomic/atomic_is_lock_free.c
diff -u /dev/null src/common/lib/libc/atomic/atomic_is_lock_free.c:1.1
--- /dev/null	Thu Mar 30 15:03:36 2023
+++ src/common/lib/libc/atomic/atomic_is_lock_free.c	Thu Mar 30 15:03:36 2023
@@ -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;
+	}
+}

Reply via email to