include/nuttx/atomic.h: Fix C++ compilation with -nostdinc++

Without c++ standard includes, the <atomic> library is not available.
GCC may use __auto_type for the C-style atomic oprations, and this
is not available for C++. Just define the __auto_type to auto for C++.

Also, the built-in _atomic functions for GCC expect "volatile" parameters
in C, but don't allow that in C++. So selecting the atomic_t and atomic64_t
types according to that.

Signed-off-by: Jukka Laitinen <jukka.laitinen@tii.ae>
This commit is contained in:
Jukka Laitinen 2025-08-05 17:15:24 +03:00 committed by Xiang Xiao
parent 2771df6250
commit 2fa607796d

View file

@ -60,8 +60,14 @@ extern "C++"
# include <stdatomic.h>
# define ATOMIC_FUNC(f, n) atomic_##f##_explicit
typedef volatile _Atomic int32_t atomic_t;
typedef volatile _Atomic int64_t atomic64_t;
# if defined(__cplusplus)
# define __auto_type auto
typedef _Atomic int32_t atomic_t;
typedef _Atomic int64_t atomic64_t;
# else
typedef volatile _Atomic int32_t atomic_t;
typedef volatile _Atomic int64_t atomic64_t;
# endif
# endif
#endif