git: 3b9fc833707c - stable/13 - atomic: Add plain atomic_load/store_bool()

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Tue, 16 Aug 2022 20:44:40 UTC
The branch stable/13 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=3b9fc833707cdcff37faba3625aa7164d6c39dbe

commit 3b9fc833707cdcff37faba3625aa7164d6c39dbe
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-08-09 20:08:29 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2022-08-16 20:34:29 +0000

    atomic: Add plain atomic_load/store_bool()
    
    Reviewed by:    kib
    Sponsored by:   The FreeBSD Foundation
    
    (cherry picked from commit 2bed73739aac352299222a18f669a03544c7c9e2)
---
 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