Low-level atomic operations for Swift
This minor release adds support for Swift 5.9.
This release contains no API-level additions nor any other visible changes to stable interfaces; the version number bump is simply acknowledging that this release ships a full rewrite of package internals -- it isn't just a regular bug fix release.
Full Changelog: https://github.com/apple/swift-atomics/compare/1.1.0...1.2.0
Thank you very much to everyone who contributed to this release!
This minor release improves support for recent Swift releases, adds new functionality and resolves some known issues.
This release requires Swift 5.6 or better. (Clients on older toolchains will automatically remain on the 1.0 releases.) (#67)
AtomicReference
is now unconditionally available on all supported platforms. (#65 by @kelvin13)
ManagedAtomic
now conforms to Sendable
when its Value
is Sendable
. (#45)
RawRepresentable
types can now opt into support for atomic operations on their optional values as long as their underlying RawValue
also supports it. (#42 by @glessard)
struct SomeValue: RawRepresentable, AtomicOptionalWrappable {
var rawValue: UnsafeRawPointer
init(rawValue: UnsafeRawPointer) {
self.rawValue = rawValue
}
}
let atomic: ManagedAtomic<SomeValue> // OK
let atomic2: ManagedAtomic<SomeValue?> // Also OK!
The weakCompareExchange
operation now comes with a variant that takes a single ordering (#75). This makes it less verbose to use it in the common case where the same ordering is needed on both the success and the failure paths.
let atomic = ManagedAtomic<Int>(42)
var original = 0
var exchanged = false
repeat {
(exchanged, original) = atomic.weakCompareExchange(
expected: original,
desired: 23,
ordering: .relaxed) // no need to specify a separate failureOrdering!
} while !exchanged
DoubleWord.low
and DoubleWord.high
are now deprecated (#70). Use first
and second
instead.
This release lays the groundwork for replacing the use of C atomics with native Swift compiler intrinsics (#74). When it eventually becomes stable, this change will allow swift-atomics to support Windows (#56), and it will resolve a multitude of build problems on other platforms (e.g., #54, #55, #62, #8). Version 1.1 ships with experimental support for building the package in this mode; however, this mode is not enabled by default, and it is subject to arbitrarily change in any future release.
ManagedAtomicLazyReference
no longer leaks its value when it is deinitialized (#66).
AtomicReference
conformances on non-final classes no longer emit a compiler warning in Swift 5.7 and later (#53). Atomic references now fully support class hierarchies, but only the superclass that introduced the AtomicReference
conformance can be used as the type argument to ManagedAtomic
or UnsafeAtomic
. This turns a previously undiagnosed type safety violation into an unconditional compile-time error:
class Base: AtomicReference {}
// 1.0: warning: Non-final class 'Base' cannot safely conform to protocol
// 'AtomicValue', which requires that 'Self.AtomicRepresentation.Value'
// is exactly equal to 'Self'; this is an error in Swift 6
// 1.1: OK
class Derived: Base {}
let ref1: ManagedAtomic<Base> = .init(Derived()) // OK
let ref2: ManagedAtomic<Derived> = .init(Derived())
// 1.0:
// no error, silent type safety violation
// 1.1+:
// error: 'ManagedAtomic' requires the types 'Derived'
// and 'Base' be equivalent
All atomic operations are now implemented in terms of Int8
, Int16
, Int32
, Int64
, Int
, or DoubleWord
. The package no longer uses non-standard C to implement atomic operations on Bool
(#37).
Building the package tests is now far less resource-intensive, considerably speeding up builds on some memory-constrained systems (#71).
Full diffs: https://github.com/apple/swift-atomics/compare/1.0.3...1.1.0
Thank you very much to everyone who contributed to this release!
This is a documentation update, including the addition of basic DocC documentation bundles. The only other change is a fix to the CMake build configuration.
The package now contains documentation bundles, enabling nicer presentation of API documentation in DocC.
Full Changelog: https://github.com/apple/swift-atomics/compare/1.0.2...1.0.3
This is a patch release that introduces initial support for building this package with the Swift 5.5 compiler.
(More fully-featured support with additional Sendable
conformances will come in a future minor release.)
UnsafeAtomic
and UnsafeAtomicLazyReference
now only conform to Sendable
when their value is. Swift 5.5 implicitly adds unconditional conformances to these types in 1.0.1, which isn't right. (#47)UnsafeAtomic
's Sendable
conformance (by @lorentey)Thank you to everyone who contributed to this release!
This is a patch release containing several bug fixes.
@frozen
to match their @inlinable
initializers. (This package isn't ABI stable, so this change is a no-op in all supported configurations.)Thank you to everyone who contributed to this release!
This release marks an important milestone for this package -- the advent of source stability!
Thank you to everyone who contributed to this release!
On Linux only, support for double-wide atomics is unavailable by default on x86_64 CPUs. To enable double-wide atomic functionality, you have to manually switch on support for the cmpxchg16b
instruction:
$ swift build -Xcc -mcx16 -Xswiftc -DENABLE_DOUBLEWIDE_ATOMICS -c release
Code containing cmpxchg16b
will run on all but the earliest AMD x86_64 CPUs. (You can verify your target CPU supports it by checking that the cx16
flag is present in /proc/cpuinfo.)
The Swift Atomics test suite now requires --enable-test-discovery
on non-Apple platforms.
Initial release.