feat(sync): added atomic<T> and atomic_ref<T> wrapper primitives over raw atomic builtins - #176
Merged
Merged
Conversation
… raw atomic builtins
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
__atomic_*builtins with a memory order argument repeated at every call site, making orderings easy to get wrong and overall looked messy as hell.sync::atomic<T>(owned, non-copyable) andsync::atomic_ref<T>(borrowed view of plain storage) encode the ordering in the method name and reject non-lock-free types at compile time.Note
Medium Risk
Changes memory-order spelling and refcount/futex/spinlock synchronization paths; semantics are intended to match prior builtins but mistakes here affect core locking and object lifetime.
Overview
Introduces
sync::atomic<T>andsync::atomic_ref<T>as typed wrappers over GCC__atomic_*builtins, with memory order encoded in method names (load_acquire,fetch_sub_release, etc.) and compile-time lock-free requirements for 1/2/4/8-byte integers, enums, and pointers.atomic_fence_acquire/atomic_fence_releasereplace ad-hoc thread fences.ref_countedstores the refcount insync::atomic<uint32_t>instead of a plainuint32_twith raw builtins;try_add_refnow treatsREFCOUNT_POISONlike zero (returns false), and the last-ref path usessync::atomic_fence_acquirebefore poisoning.Ticket spinlocks in
spinlock.huseatomic_ref<uint16_t>onnext_ticketandnow_servingwith the same relaxed/acquire/release pattern as before.futex_waitre-reads the user futex word under the bucket lock viaatomic_ref<uint32_t>::load_relaxed()instead ofmemcpy, keeping the atomic check-and-enqueue behavior while spelling the read as an atomic load.Reviewed by Cursor Bugbot for commit 9a5eb48. Bugbot is set up for automated code reviews on this repo. Configure here.