zhangyu-duck opened a new pull request, #19802:
URL: https://github.com/apache/nuttx/pull/19802

    ---
     Summary
   
     This PR reworks the atomic operation implementation in <nuttx/atomic.h> to 
provide a unified, portable, and standard-conflict-free atomic interface.
   
     Key changes:
   
     1. Use toolchain builtin atomic functions instead of 
<atomic>/<stdatomic.h>. The original implementation relied on 
__has_include(<atomic>) and C11 version checks, which is not portable (e.g., 
Tasking compiler doesn't support __has_include). It
     also conflicts with third-party C++ libraries that include <atomic> — the 
standard library expects template types while NuttX atomic_t is int32_t, 
causing compile errors. The new implementation calls compiler builtins 
(__atomic_* / __c11_atomic_*
      / _Interlocked*) directly, similar to Zephyr.
     2. Rename atomic_fetch_xxx to atomic_xxx (e.g., atomic_fetch_add → 
atomic_add). The atomic_fetch_xxx naming is reserved by the C/C++ standard. 
Since source files may directly or indirectly include <nuttx/atomic.h>, keeping 
the standard name
     causes function name conflicts and compile errors. Other non-standard API 
names (e.g., atomic_read, atomic_set, atomic_xchg) remain unchanged.
     3. Add four selectable atomic backends via Kconfig:
       - LIBC_ATOMIC_TOOLCHAIN — compiler builtins (default, lock-free)
       - LIBC_ATOMIC_ARCH — arch-native atomic instructions (lock-free)
       - LIBC_ATOMIC_HWSPINLOCK — hardware spinlock wrapping critical section 
(cross-core, for chips without atomic instructions but with hwspinlock 
peripheral)
       - LIBC_ATOMIC_IRQ — IRQ disable wrapping critical section (single-core 
only, fallback for ARMv6-M / ARM7TDMI / ARM926EJS etc.)
     4. Add hwspinlock-based atomic for cxd56, rp2040, and lc823450 (multi-core 
capable chips).
     5. Use _Atomic qualifier for atomic_t typedef when the compiler supports 
it, with a __Atomic(t) wrapper for clang compatibility.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to