Releases: glessard/swift-atomics
Tweaks to compare-and-exchange functions
Move choice between weak and strong CAS out of the C parameter list in CAtomics
-
In the
CAtomics
module, all types have directCompareAndExchangeWeak
andCompareAndExchangeStrong
functions rather than a single function with a parameter selecting between strong and weak. -
The old version of
CompareAndExchange
with aCASType
parameter still exists, but forwards to either of the other two, making it objectively worse. -
SwiftAtomics
internally adapts to the above, but is otherwise unchanged.
Fix for Windows
- use
intptr_t
in tagged pointer unions.
Simplifications, mostly.
-
Changes the default memory ordering parameters in SwiftAtomics. The defaults are now
.acquire
for loading operations,.release
for storing operations, and.acqrel
for read-modify-write operations. -
Removes the
load()
function onAtomicReference
.
load
required locking, and it failed once every several million attempts (under contention), and that just wasn't good enough. (It fails seldom enough that what I thought had been extensive testing prior to version 4.2.0 was in fact insufficient.) There's been a fair bit of trying to fix it in the last year, but nothing has completely worked. The correct solution may require collaboration with Swift's ARC reference-counting runtime, and therefore will have to wait until a similar type appears in the standard library.
Version 5
This release has major changes to the CAtomics
package, in that it no longer uses swift-style function names, but uses (once more) C-style names: it switches from using the SWIFT_NAME
macro to __attribute__((overloadable))
. This allows all the necessary changes to have a similar shape, as
AtomicInt.load(_ order: LoadMemoryOrder)
becomes
CAtomicsLoad(_ atomic: UnsafeMutablePointer<AtomicInt>, order: LoadMemoryOrder)
.
The Swift-style module is renamed to SwiftAtomics
, which is less presumptuous than just Atomics
.
(Still presumptuous, but the standard library is unlikely to ever have a module named SwiftAtomics
.)
Finally, tagged pointers are now usable from the SwiftAtomics
module, after having been usable from CAtomics
since 4.4.0
.
Fix for Swift 5 compiler
- The Swift 5 compiler no longer imports structs with large alignments.
This defeats the approach I previously took to pad structs. - In order to get padded structs to mitigate false sharing effects, the package
now inserts explicit padding rather than explicitly requesting a large alignment.
This is not the ideal solution, but it's good enough for most cases. - The padded types are renamed from 4.4.0, with abject apologies to anyone
who might be affected. I should have tried building with Swift 5 a tad earlier.
4.4.0
- Adds tagged pointers to the CAtomics package, taking advantage of 128-bit atomic instructions in x64 and ARM64
- Adds cache-aligned variants to various types from CAtomics. These types take an entire cache line to themselves, which can be useful in some cases.
- Adds initializers, such as
AtomicInt32.init(_ value: Int32)
andAtomicRawPointer.init(_ pointer: UnsafeRawPointer)
. Previously one had to use a default initializer followed by a call to theinitialize
method. - Adds a compare-and-swap operation to
AtomicReference
- Supports the Windows build of Swift
Improvements for Swift 4.2
Merge pull request #21 from glessard/devel update CI configuration
Improvements for Swift 4.1
Improved CAtomics
The underlying C package has a nicer interface when used from Swift.