nuttx: rework atomic operations - #19802
Closed
zhangyu-duck wants to merge 7 commits into
Closed
Conversation
zhangyu-duck
requested review from
Donny9,
GUIDINGLI,
acassis,
anchao,
davids5,
eren-terzioglu,
fdcavalcanti,
gustavonihei,
hartmannathan,
jerpelea,
johannes-nivus,
liuguo09,
lupyuen,
masayuki2009,
pkarashchenko,
pussuw,
tmedicci,
xiaoxiang781216 and
yamt
as code owners
August 12, 2026 07:51
zhangyu-duck
marked this pull request as draft
August 12, 2026 07:52
jerpelea
requested changes
Aug 12, 2026
jerpelea
left a comment
Contributor
There was a problem hiding this comment.
please follow contribution guidelines and provide proper PR description, impact and testing
zhangyu-duck
force-pushed
the
atomic-upstream
branch
from
August 12, 2026 08:07
4d94b05 to
29c889b
Compare
|
… be achieved by switching interrupts, this version does not support SMP VELAPLATFO-66334 Change-Id: I0817567aabfa370a8eb7798b0a5ab8c8f2e550b2 Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Refine the atomic Kconfig to support multiple backends: LIBC_ATOMIC_TOOLCHAIN (compiler builtins), LIBC_ATOMIC_ARCH (arch instructions), and LIBC_ATOMIC_IRQ (interrupt disable). Rename arch_atomic.c to arch_atomic_irq.c since it supports the IRQ backend. Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
zhangyu-duck
force-pushed
the
atomic-upstream
branch
from
August 14, 2026 03:35
29c889b to
1b6e3a3
Compare
Select LIBC_ATOMIC_IRQ at the architecture level (ARM7TDMI, ARM926EJS, ARMv6M) for chips that do not support atomic operations natively. This covers all ARM7TDMI, ARM926EJS, and Cortex-M0 based chips automatically. Also select LIBC_ATOMIC_IRQ for specific non-ARM architectures (AVR, RISC-V, SPARC, Xtensa) that lack atomic instruction support. Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
VELAPLATFO-77769 Change-Id: I88642ef6b8882eabc98169aeabb8dd8f22e0ae7c Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Add hardware spinlock driver implementations for cxd56, rp2040, and lc823450 chips. These drivers provide the hwspinlock_ops_s interface used by the atomic hwspinlock backend. Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Implement atomic_lock/atomic_unlock using hwspinlock when CONFIG_LIBC_ATOMIC_HWSPINLOCK is selected, and using up_irq_save/ up_irq_restore when CONFIG_LIBC_ATOMIC_IRQ is selected. Rename arch_atomic_irq.c to arch_atomic.c. Select LIBC_ATOMIC_HWSPINLOCK for SMP on RP2040 which has hardware spinlock support for multi-core atomic operations. Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
Add per-chip atomic hwspinlock device definitions for cxd56, rp2040, and lc823450. These provide the hardware spinlock device used by the atomic hwspinlock backend for multi-core atomic operations. Signed-off-by: zhangyu117 <zhangyu117@xiaomi.com>
zhangyu-duck
force-pushed
the
atomic-upstream
branch
from
August 14, 2026 05:33
1b6e3a3 to
7995fa4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
also conflicts with third-party C++ libraries that include — 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.
causes function name conflicts and compile errors. Other non-standard API names (e.g., atomic_read, atomic_set, atomic_xchg) remain unchanged.
- 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.)