os(atomic): add portable pointer-width CAS __os_atomic_cas_ptr#33
Merged
Conversation
Add a pointer-width compare-and-swap to the atomic layer, which until now exposed only 32-bit and 64-bit integer CAS. Native implementations in the GCC __atomic and legacy __sync builtin tiers (over intptr_t, whose codegen is more uniform than pointer-typed C11 atomics and is value-preserving for object pointers). A generic fallback synthesizes it from the tier's sized CAS (64-bit when pointers are 8 bytes, else 32-bit), the mutex-emulated atomic-pool mutex when there are no native atomics, or a plain store in the single-threaded build. This is foundational for lock-free/RCU data structures (Treiber stacks, epoch reclamation) used in the multi-core scaling work. No current caller; added as the substrate the RCU-for-shared-structures track builds on.
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.
What
Add a pointer-width compare-and-swap,
__os_atomic_cas_ptr, to the atomiclayer. Until now the layer exposed only 32-bit and 64-bit integer CAS.
How
__atomicand legacy__syncbuiltintiers, expressed over
intptr_t. Integer atomics have more uniform codegenthan pointer-typed C11 atomics and are value-preserving for object pointers.
the 64-bit CAS when pointers are 8 bytes, otherwise the 32-bit CAS; the
mutex-emulated atomic-pool mutex when no native atomics are configured; or a
plain store in the single-threaded build.
os_ext.hunder the matching tier guards.Status
No current caller. This lands the primitive as the substrate that lock-free
and RCU data structures (Treiber stacks, epoch reclamation) in the multi-core
scaling work will build on. It depends on real hardware atomics, which #32
made available on modern toolchains.
Verification
Builds clean on top of current master (meson, macOS clang, GCC
__atomictier);
__os_atomic_cas_ptris present as a native text symbol. On x86_64 itcompiles to a single
lock cmpxchg.