git: 2bed73739aac - main - atomic: Add plain atomic_load/store_bool()

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 09 Aug 2022 23:02:47 UTC
The branch main has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=2bed73739aac352299222a18f669a03544c7c9e2

commit 2bed73739aac352299222a18f669a03544c7c9e2
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-08-09 20:08:29 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-08-09 22:34:01 +0000

    atomic: Add plain atomic_load/store_bool()
    
    Reviewed by:    kib
    MFC after:      1 week
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D36078
---
 sys/sys/atomic_common.h | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/sys/sys/atomic_common.h b/sys/sys/atomic_common.h
index a34198fda88a..04281ae8f2ed 100644
--- a/sys/sys/atomic_common.h
+++ b/sys/sys/atomic_common.h
@@ -39,6 +39,10 @@
 #include <sys/cdefs.h>
 #include <sys/types.h>
 
+#define	__atomic_load_bool_relaxed(p)	(*(volatile _Bool *)(p))
+#define	__atomic_store_bool_relaxed(p, v)	\
+    (*(volatile _Bool *)(p) = (_Bool)(v))
+
 #define	__atomic_load_char_relaxed(p)	(*(volatile u_char *)(p))
 #define	__atomic_load_short_relaxed(p)	(*(volatile u_short *)(p))
 #define	__atomic_load_int_relaxed(p)	(*(volatile u_int *)(p))
@@ -70,6 +74,11 @@
  */
 #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L) || \
     __has_extension(c_generic_selections)
+#define	atomic_load_bool(p)			\
+	_Generic(*(p), _Bool: __atomic_load_bool_relaxed(p))
+#define	atomic_store_bool(p, v)			\
+	_Generic(*(p), _Bool: __atomic_store_bool_relaxed(p, v))
+
 #define	__atomic_load_generic(p, t, ut, n)	\
 	_Generic(*(p),				\
 	    t: __atomic_load_ ## n ## _relaxed(p), ut: __atomic_load_ ## n ## _relaxed(p))
@@ -77,6 +86,8 @@
 	_Generic(*(p),				\
 	    t: __atomic_store_ ## n ## _relaxed(p, v), ut: __atomic_store_ ## n ## _relaxed(p, v))
 #else
+#define	atomic_load_bool(p)			__atomic_load_bool_relaxed(p)
+#define	atomic_store_bool(p, v)			__atomic_store_bool_relaxed(p, v)
 #define	__atomic_load_generic(p, t, ut, n)	__atomic_load_ ## n ## _relaxed(p)
 #define	__atomic_store_generic(p, v, t, ut, n)	__atomic_store_ ## n ## _relaxed(p, v)
 #endif