apple / swift-atomics

Low-level atomic operations for Swift
Apache License 2.0
1.06k stars 50 forks source link

Add a `weakCompareExchange` taking only one ordering #75

Closed lorentey closed 1 year ago

lorentey commented 1 year ago

I omitted this because I didn't expect it would be needed, but I've found myself reaching for it surprisingly often over the years.

protocol AtomicStorage {
  ...
  @_semantics("atomics.requires_constant_orderings")
  static func atomicWeakCompareExchange(
    expected: Value,
    desired: __owned Value,
    at pointer: UnsafeMutablePointer<Self>,
    ordering: AtomicUpdateOrdering
  ) -> (exchanged: Bool, original: Value)
}

This can ~trivially forward to the existing requirement by default, but we'll want actual implementations anyway.