Repository navigation
include/atomic: add atomic_ptr_t and release_acquire cmpxchg - #21843
Merged
Merged
Conversation
CV-Bowen
requested review from
masayuki2009 and
xiaoxiang781216
as code owners
November 13, 2026 13:58
xiaoxiang781216
approved these changes
Nov 13, 2026
GUIDINGLI
approved these changes
Nov 13, 2026
|
Add atomic_ptr_t that maps to atomic_t on 32-bit platforms and atomic64_t on 64-bit platforms based on UINTPTR_MAX. All atomic_ptr_xx operations (set, read, add, sub, and, or, xor, xchg, cmpxchg, try_cmpxchg with memory order variants) are mapped to the corresponding atomic_xx or atomic64_xx macros accordingly. Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
Add atomic_cmpxchg_release_acquire and atomic_try_cmpxchg_release_acquire macros for 32-bit, 64-bit, and pointer-width atomic operations. This variant uses RELEASE on CAS success and ACQUIRE on CAS failure, matching the memory ordering used by DPDK's RTS ring tail-commit CAS where the failure path must re-acquire visibility of updates from other threads before retrying. Signed-off-by: Bowen Wang <wangbowen6@xiaomi.com>
CV-Bowen
force-pushed
the
up/P93-atomic
branch
from
November 14, 2026 14:59
da1fa7c to
56e5f04
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
Two additions to
include/nuttx/atomic.h, needed by the lock-free ring(
include/nuttx/ring.h) that will follow in a separate PR.include/atomic: add atomic_ptr_t type and operations: a pointer-widthatomic type. It maps to
atomic_twhenUINTPTR_MAX <= UINT32_MAXand to
atomic64_totherwise, and everyatomic_ptr_xxx()operation(set/read/add/sub/and/or/xor/xchg/cmpxchg/try_cmpxchg, with their
memory-order variants) maps to the matching
atomic_xxx()/atomic64_xxx()macro.include/atomic: add cmpxchg_release_acquire memory order variant:atomic[64|_ptr]_[try_]cmpxchg_release_acquire(), a CAS that usesRELEASE on success and ACQUIRE on failure. The ring's tail-commit CAS
(the DPDK RTS scheme) needs it: on failure the loop retries with the
value another thread published, so it must acquire that thread's
writes. The existing
_releasevariant is RELAXED on failure.Impact
include/nuttx/atomic.hnow includes<stdint.h>forUINTPTR_MAX.libs/libc/machine/arch_atomic.cfallback already take separatesuccess/failure orders, so the new variant only passes different
constants to the existing
atomic_compare_exchange_[4|8]().Testing
Host: Ubuntu 22.04.5 LTS x86_64; sim: gcc 13.1.0; qemu-armv7a: arm-none-eabi-gcc 10.3.1, QEMU 6.2.0; qemu-armv8a: aarch64-none-elf-gcc 12.2.1, QEMU 10.2.1
No in-tree user yet, so the macros were exercised by a small probe that
temporarily replaced
apps/testing/libc/atomic/atomic_main.c(not part ofthis PR). It checks
sizeof(atomic_ptr_t) == sizeof(void *), everyatomic_ptr_*read-modify-write against its expected old/new value, andfor each
*_cmpxchg_release_acquire()/*_try_cmpxchg_release_acquire()both the success path (value replaced) and the failure path (value
untouched,
expectedupdated to the current value).Configured with
CONFIG_TESTING_ATOMIC=yon top of:sim:nshqemu-armv7a:nshqemu-armv8a:nsh_smp(-smp 4)Probe source (drop-in for testing/libc/atomic/atomic_main.c)
Output
Not run: a
CONFIG_LIBC_ATOMIC_TOOLCHAIN=ntarget (e.g. Cortex-M0).That path goes through the same
atomic_compare_exchange_[4|8]()that theexisting
_acquire/_releasevariants already use.No regression in rpmsg: sim:rpserver/rpproxy and qemu-armv8a:rpserver/rpproxy boot and pass the fixed rpmsg cases (dump, ping, rpmsgfs; 15/15). qemu-armv8a was built with LIBC_ENVPATH and BINFMT_CHECKEXEC disabled, which current master needs for nxinit to start nsh there; unrelated to this change.