aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFaraz Vahedi <kfv@kfv.io>2026-05-07 23:00:47 +0000
committerWarner Losh <imp@FreeBSD.org>2026-06-20 00:23:29 +0000
commit54ac231419cf09557d2f5826b1539e83db552410 (patch)
treee818d05dcbe565ec45e3437b321a6c02bcb445c3
parent640ddf8571291ab2965de85f67e6065a4d7efbf8 (diff)
libc: Fix atomic_init for GCC atomic objects
Add a dedicated `__GNUC_ATOMICS` path that initialises via `atomic_store_explicit(obj, value, memory_order_relaxed)`. This ensures the required initialisation semantics without assuming any particular object representation. Previously, `atomic_init` on GCC fell through to the legacy `__val` member path intended only for old struct-backed atomic objects. For current atomic objects, this caused the following compilation error: > error: request for member '__val' in something not a structure or union As a result, valid code such as `atomic_init(&x, 1)` failed to compile when using GCC. This fix restores compatibility with standard-conforming callers while other code paths remain unchanged. Signed-off-by: Faraz Vahedi <kfv@kfv.io> Reviewed by: imp Pull Request: https://github.com/freebsd/freebsd-src/pull/2185
-rw-r--r--sys/sys/stdatomic.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/sys/sys/stdatomic.h b/sys/sys/stdatomic.h
index 3e4bdd505418..c0cbb7f785b5 100644
--- a/sys/sys/stdatomic.h
+++ b/sys/sys/stdatomic.h
@@ -96,6 +96,9 @@
#if defined(__CLANG_ATOMICS)
#define atomic_init(obj, value) __c11_atomic_init(obj, value)
+#elif defined(__GNUC_ATOMICS)
+#define atomic_init(obj, value) atomic_store_explicit(obj, \
+ value, __ATOMIC_RELAXED)
#else
#define atomic_init(obj, value) ((void)((obj)->__val = (value)))
#endif