apple / swift-atomics

Low-level atomic operations for Swift
Apache License 2.0
1.08k stars 51 forks source link

Update AtomicOptionalWrappable support for RawRepresentable types #73

Closed lorentey closed 1 year ago

lorentey commented 1 year ago

Also add some basic tests exercising these.

With this in place, RawRepresentable types whose RawValue is AtomicOptionalWrappable can also opt into "atomic optional wrappability" by simply conforming to the protocol -- no need to define any members:

struct Hyacinth: RawRepresentable, AtomicOptionalWrappable {
  var rawValue: UnsafeRawPointer

  init(rawValue: UnsafeRawPointer) {
    self.rawValue = rawValue
  }
}

let ref = ManagedAtomic<Hyacinth?>(nil) // OK!
ref.store(Hyacinth(rawValue: p)!, ordering: .relaxed) // OK!

Checklist

lorentey commented 1 year ago

@swift-ci test

lorentey commented 1 year ago

@swift-ci test

lorentey commented 1 year ago

@swift-ci test