Skip to content

feat(sync): added atomic<T> and atomic_ref<T> wrapper primitives over raw atomic builtins - #176

Merged
FlareCoding merged 1 commit into
masterfrom
pr/sync-atomic-primitive
Aug 26, 2026
Merged

feat(sync): added atomic<T> and atomic_ref<T> wrapper primitives over raw atomic builtins#176
FlareCoding merged 1 commit into
masterfrom
pr/sync-atomic-primitive

Conversation

@FlareCoding

@FlareCoding FlareCoding commented Aug 26, 2026

Copy link
Copy Markdown
Owner

Summary

  • Atomic access was spelled as raw __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) and sync::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> and sync::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_release replace ad-hoc thread fences.

ref_counted stores the refcount in sync::atomic<uint32_t> instead of a plain uint32_t with raw builtins; try_add_ref now treats REFCOUNT_POISON like zero (returns false), and the last-ref path uses sync::atomic_fence_acquire before poisoning.

Ticket spinlocks in spinlock.h use atomic_ref<uint16_t> on next_ticket and now_serving with the same relaxed/acquire/release pattern as before.

futex_wait re-reads the user futex word under the bucket lock via atomic_ref<uint32_t>::load_relaxed() instead of memcpy, 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.

@FlareCoding
FlareCoding merged commit f328a52 into master Aug 26, 2026
19 checks passed
@FlareCoding
FlareCoding deleted the pr/sync-atomic-primitive branch August 26, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant