Migrate atomics to Synchronization.Atomic, drop ToolsProtocolsCAtomics#51
Merged
rintaro merged 2 commits intoMay 27, 2026
Merged
Conversation
ahoppen
approved these changes
May 22, 2026
Member
ahoppen
left a comment
There was a problem hiding this comment.
Very nice. We should also be able to get rid of ThreadSafeBox in favor of Mutex.
6115421 to
a10b3db
Compare
Replace the AtomicBool/UInt8/UInt32/Int32 wrapper classes (backed by a small C atomics shim) with Synchronization.Atomic<T>. All sites use .sequentiallyConsistent ordering to match the prior shim's behavior; relaxing per-site is left as a follow-up. The ToolsProtocolsCAtomics target is removed from Package.swift and CMake.
The previous .sequentiallyConsistent ordering on every atomic forced unnecessary barriers (notably dmb ish on ARM). Replace with the minimum ordering each operation actually needs: - ID counters (request/notification/signpost) → .relaxed. Operations only need uniqueness; ordering relative to other memory carries no information. - LoggingScope's "fault logged" once-flag → .relaxed. No associated state rides on the flag. - RequestAndReply.replied → .acquiring on load, .acquiringAndReleasing on exchange. ARC's refcount synchronization in deinit would make .relaxed functionally correct, but acquire/release expresses the operation's intent without leaning on that side-channel.
a10b3db to
1ea99da
Compare
hamishknight
approved these changes
May 22, 2026
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.
Replace the
AtomicBool/UInt8/UInt32/Int32wrapper classes (backed by a small C atomics shim) withSynchronization.Atomic<T>. TheToolsProtocolsCAtomicstarget is removed from Package.swift and CMake.Also relax atomic memory orderings to
.relaxed. Every atomic in this package is either a unique-ID counter or a "once" flag whose result no other memory reads ride on. None of them synchronize with adjacent non-atomic state, so.relaxedis sufficient and avoids theSEQ_CSTbarriers.