diff --git a/CMakeLists.txt b/CMakeLists.txt index a22ece0..f0a5a1c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,6 +25,18 @@ endif() include(CTest) include(SwiftSupport) +set(ATOMICS_SWIFT_FLAGS) +set(ATOMICS_C_FLAGS) + +if(CMAKE_Swift_COMPILER_VERSION VERSION_GREATER_EQUAL 5.9) + list(APPEND ATOMICS_SWIFT_FLAGS + "-enable-experimental-feature BuiltinModule" + "-DATOMICS_NATIVE_BUILTINS" + "-Xcc" "-DATOMICS_NATIVE_BUILTINS=1") + list(APPEND ATOMICS_C_FLAGS + "-DATOMICS_NATIVE_BUILTINS=1") +endif() + add_subdirectory(Sources) if(BUILD_TESTING) add_subdirectory(Tests) diff --git a/README.md b/README.md index 5f368e3..5afb7f3 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ The primary focus is to provide systems programmers access to atomic operations - Each atomic operation is invoked in client code using a clear, unabbreviated name that directly specifies what that operation does. Atomic operations are never implicit -- they are always clearly spelled out. -- There is no default memory ordering, to avoid accidental (and costly) use of sequential consistency. (This is surprisingly common issue in C/C++.) +- There is no default memory ordering, to avoid accidental (and costly) use of sequential consistency. (This is a surprisingly common issue in C/C++.) - Operations such as compare/exchange prefer to keep input values cleanly separated from results. There are no `inout` parameters. @@ -56,7 +56,7 @@ The primary focus is to provide systems programmers access to atomic operations To use `Atomics` in your own project, you need to set it up as a package dependency: ```swift -// swift-tools-version:5.6 +// swift-tools-version:5.9 import PackageDescription let package = Package( @@ -64,7 +64,7 @@ let package = Package( dependencies: [ .package( url: "https://github.com/apple/swift-atomics.git", - .upToNextMajor(from: "1.1.0") // or `.upToNextMinor + .upToNextMajor(from: "1.2.0") // or `.upToNextMinor ) ], targets: [ @@ -78,20 +78,76 @@ let package = Package( ) ``` +## Compatibility + +### Swift Releases + +The atomics implementation is inherently far more tightly coupled to the compiler than usual, so tagged versions of this package typically only support a narrow range of Swift releases: + +swift-atomics | Supported Swift Versions +--------------------|------------------------- +`1.0.x` | 5.3, 5.4, 5.5 +`1.1.x` | 5.6, 5.7, 5.8 +`1.2.x` | 5.7, 5.8, 5.9 +`main` | 5.8, 5.9, unreleased snapshots of 5.10 and trunk + +Note that the `main` branch is not a tagged release, so its contents are inherently unstable. Because of this, we do not recommended using it in production. (For example, its set of supported Swift releases is subject to change without notice.) + +### Source Stability + +The Swift Atomics package is source stable. The version numbers follow [Semantic Versioning][semver] -- source breaking changes to public API can only land in a new major version. + +[semver]: https://semver.org + +The public API of current versions of the `swift-atomics` package consists of non-underscored declarations that are marked `public` in the `Atomics` module. + +By "underscored declarations" we mean declarations that have a leading underscore anywhere in their fully qualified name. For instance, here are some names that wouldn't be considered part of the public API, even if they were technically marked public: + +- `FooModule.Bar._someMember(value:)` (underscored member) +- `FooModule._Bar.someMember` (underscored type) +- `_FooModule.Bar` (underscored module) +- `FooModule.Bar.init(_value:)` (underscored initializer) + +Interfaces that aren't part of the public API may continue to change in any release, including patch releases. + +Note that contents of the `_AtomicsShims` module explicitly aren't public API. (As implied by its underscored module name.) The definitions therein may therefore change at whim, and the entire module may be removed in any new release -- do not import this module directly. We also don't make any source compatibility promises about the contents of the `Utilities`, `Tests`, `Xcode` and `cmake` subdirectories. + +If you have a use case that requires using underscored APIs, please [submit a Feature Request][enhancement] describing it! We'd like the public interface to be as useful as possible -- although preferably without compromising safety or limiting future evolution. + +Future minor versions of the package may introduce changes to these rules as needed. + +We'd like this package to quickly embrace Swift language and toolchain improvements that are relevant to its mandate. Accordingly, from time to time, new versions of this package will require clients to upgrade to a more recent Swift toolchain release. (This allows the package to make use of new language/stdlib features, build on compiler bug fixes, and adopt new package manager functionality as soon as they are available.) + +Requiring a new Swift release will only require a minor version bump. + + ## Features -The package implements atomic operations for the following Swift constructs, all of which conform to the public `AtomicValue` protocol: +For a detailed overview of the interfaces offered by this package, please see [our API documentation][APIDocs]. + +[APIDocs]: https://swiftpackageindex.com/apple/swift-atomics/1.2.0/documentation/atomics +[AtomicValue]: https://swiftpackageindex.com/apple/swift-atomics/1.2.0/documentation/atomics/atomicvalue +[DoubleWord]: https://swiftpackageindex.com/apple/swift-atomics/1.2.0/documentation/atomics/doubleword +[AtomicReference]: https://swiftpackageindex.com/apple/swift-atomics/1.2.0/documentation/atomics/atomicreference +[UnsafeAtomic]: https://swiftpackageindex.com/apple/swift-atomics/1.2.0/documentation/atomics/unsafeatomic +[ManagedAtomic]: https://swiftpackageindex.com/apple/swift-atomics/1.2.0/documentation/atomics/managedatomic +[ManagedAtomicLazyReference]: https://swiftpackageindex.com/apple/swift-atomics/1.2.0/documentation/atomics/managedatomiclazyreference +[UnsafeAtomicLazyReference]: https://swiftpackageindex.com/apple/swift-atomics/1.2.0/documentation/atomics/unsafeatomiclazyreference +[AtomicStorage]: https://swiftpackageindex.com/apple/swift-atomics/1.2.0/documentation/atomics/atomicstorage +[AtomicInteger]: https://swiftpackageindex.com/apple/swift-atomics/1.2.0/documentation/atomics/atomicinteger + +The package implements atomic operations for the following Swift constructs, all of which conform to the public [`AtomicValue` protocol][AtomicValue]: - Standard signed integer types (`Int`, `Int64`, `Int32`, `Int16`, `Int8`) - Standard unsigned integer types (`UInt`, `UInt64`, `UInt32`, `UInt16`, `UInt8`) - Booleans (`Bool`) - Standard pointer types (`UnsafeRawPointer`, `UnsafeMutableRawPointer`, `UnsafePointer`, `UnsafeMutablePointer`), along with their optional-wrapped forms (such as `Optional>`) - Unmanaged references (`Unmanaged`, `Optional>`) -- A special `DoubleWord` type that consists of two `UInt` values, `first` and `second`, providing double-wide atomic primitives +- A special [`DoubleWord` type][DoubleWord] that consists of two `UInt` values, `first` and `second`, providing double-wide atomic primitives - Any `RawRepresentable` type whose `RawValue` is in turn an atomic type (such as simple custom enum types) -- Strong references to class instances that opted into atomic use (by conforming to the `AtomicReference` protocol) +- Strong references to class instances that opted into atomic use (by conforming to the [`AtomicReference` protocol][AtomicReference]) -Of particular note is full support for atomic strong references. This provides a convenient memory reclamation solution for concurrent data structures that fits perfectly with Swift's reference counting memory management model. (Atomic strong references are implemented in terms of `DoubleWord` operations.) However, accessing an atomic strong reference is (relatively) expensive, so we also provide a separate set of efficient constructs (`ManagedAtomicLazyReference` and `UnsafeAtomicLazyReference`) for the common case of a lazily initialized (but otherwise constant) atomic strong reference. +Of particular note is full support for atomic strong references. This provides a convenient memory reclamation solution for concurrent data structures that fits perfectly with Swift's reference counting memory management model. (Atomic strong references are implemented in terms of `DoubleWord` operations.) However, accessing an atomic strong reference is (relatively) expensive, so we also provide a separate set of efficient constructs ([`ManagedAtomicLazyReference`][ManagedAtomicLazyReference] and [`UnsafeAtomicLazyReference`][UnsafeAtomicLazyReference]) for the common case of a lazily initialized (but otherwise constant) atomic strong reference. ### Lock-Free vs Wait-Free Operations @@ -107,12 +163,12 @@ Atomic access is implemented in terms of dedicated atomic storage representation [SE-0282]: https://github.com/apple/swift-evolution/blob/master/proposals/0282-atomics.md -While the underlying pointer-based atomic operations are exposed as static methods on the corresponding `AtomicStorage` types, we strongly recommend the use of higher-level atomic wrappers to manage the details of preparing/disposing atomic storage. This version of the library provides two wrapper types: +While the underlying pointer-based atomic operations are exposed as static methods on the corresponding [`AtomicStorage`][AtomicStorage] types, we strongly recommend the use of higher-level atomic wrappers to manage the details of preparing/disposing atomic storage. This version of the library provides two wrapper types: -- an easy to use, memory-safe `ManagedAtomic` generic class and -- a less convenient, but more flexible `UnsafeAtomic` generic struct. +- an easy to use, memory-safe [`ManagedAtomic`][ManagedAtomic] generic class and +- a less convenient, but more flexible [`UnsafeAtomic`][UnsafeAtomic] generic struct. -Both constructs provide the following operations on all `AtomicValue` types: +Both constructs provide the following operations on all [`AtomicValue`][AtomicValue] types: ```swift func load(ordering: AtomicLoadOrdering) -> Value @@ -146,7 +202,7 @@ func weakCompareExchange( ) -> (exchanged: Bool, original: Value) ``` -Integer types come with additional atomic operations for incrementing or decrementing values and bitwise logical operations. +[Integer types][AtomicInteger] come with additional atomic operations for incrementing or decrementing values and bitwise logical operations. ```swift func loadThenWrappingIncrement( @@ -247,34 +303,7 @@ func logicalXorThenLoad( For an introduction to the APIs provided by this package, for now please see the [first version of SE-0282][SE-0282r0]. -The current version of the `Atomics` module does not implement APIs for tagged atomics (see [issue #1](https://github.com/apple/swift-atomics/issues/1)), although it does expose a `DoubleWord` type that can be used to implement them. (Atomic strong references are already implemented in terms of `DoubleWord`, although in their current form they do not expose any user-customizable bits.) - -## Source Stability - -The Swift Atomics package is source stable. The version numbers follow [Semantic Versioning][semver] -- source breaking changes to public API can only land in a new major version. - -[semver]: https://semver.org - -The public API of version 1.1 of the `swift-atomics` package consists of non-underscored declarations that are marked `public` in the `Atomics` module. - -By "underscored declarations" we mean declarations that have a leading underscore anywhere in their fully qualified name. For instance, here are some names that wouldn't be considered part of the public API, even if they were technically marked public: - -- `FooModule.Bar._someMember(value:)` (underscored member) -- `FooModule._Bar.someMember` (underscored type) -- `_FooModule.Bar` (underscored module) -- `FooModule.Bar.init(_value:)` (underscored initializer) - -Interfaces that aren't part of the public API may continue to change in any release, including patch releases. - -Note that contents of the `_AtomicsShims` module explicitly aren't public API. (As implied by its underscored module name.) The definitions therein may therefore change at whim, and the entire module may be removed in any new release -- do not import this module directly. We also don't make any source compatibility promises about the contents of the `Utilities`, `Tests`, `Xcode` and `cmake` subdirectories. - -If you have a use case that requires using underscored APIs, please [submit a Feature Request][enhancement] describing it! We'd like the public interface to be as useful as possible -- although preferably without compromising safety or limiting future evolution. - -Future minor versions of the package may introduce changes to these rules as needed. - -We'd like this package to quickly embrace Swift language and toolchain improvements that are relevant to its mandate. Accordingly, from time to time, new versions of this package will require clients to upgrade to a more recent Swift toolchain release. (This allows the package to make use of new language/stdlib features, build on compiler bug fixes, and adopt new package manager functionality as soon as they are available.) - -Requiring a new Swift release will only require a minor version bump. +The current version of the `Atomics` module does not implement APIs for tagged atomics (see [issue #1](https://github.com/apple/swift-atomics/issues/1)), although it does expose a [`DoubleWord`][DoubleWord] type that can be used to implement them. (Atomic strong references are already implemented in terms of [`DoubleWord`][DoubleWord], although in their current form they do not expose any user-customizable bits.) ## Contributing to Swift Atomics diff --git a/Sources/Atomics/Atomics.docc/Extensions/AtomicRawRepresentableStorage.md b/Sources/Atomics/Atomics.docc/Extensions/AtomicRawRepresentableStorage.md index 65affa5..5cb8e68 100644 --- a/Sources/Atomics/Atomics.docc/Extensions/AtomicRawRepresentableStorage.md +++ b/Sources/Atomics/Atomics.docc/Extensions/AtomicRawRepresentableStorage.md @@ -12,6 +12,6 @@ - ``atomicLoad(at:ordering:)`` - ``atomicStore(_:at:ordering:)`` - ``atomicExchange(_:at:ordering:)`` -- ``atomicCompareExchange(expected:desired:at:ordering:)`` +- ``atomicCompareExchange(expected:desired:at:ordering:)-1teq9`` - ``atomicCompareExchange(expected:desired:at:successOrdering:failureOrdering:)`` - ``atomicWeakCompareExchange(expected:desired:at:successOrdering:failureOrdering:)`` diff --git a/Sources/Atomics/Atomics.docc/Extensions/AtomicStorage.md b/Sources/Atomics/Atomics.docc/Extensions/AtomicStorage.md index a9dde5e..ac0dfe2 100644 --- a/Sources/Atomics/Atomics.docc/Extensions/AtomicStorage.md +++ b/Sources/Atomics/Atomics.docc/Extensions/AtomicStorage.md @@ -17,5 +17,6 @@ - ``atomicStore(_:at:ordering:)`` - ``atomicExchange(_:at:ordering:)`` - ``atomicCompareExchange(expected:desired:at:ordering:)`` -- ``atomicCompareExchange(expected:desired:at:successOrdering:failureOrdering:)`` +- ``atomicCompareExchange(expected:desired:at:successOrdering:failureOrdering:)-9t4wj`` +- ``atomicWeakCompareExchange(expected:desired:at:ordering:)-55229`` - ``atomicWeakCompareExchange(expected:desired:at:successOrdering:failureOrdering:)`` diff --git a/Sources/Atomics/Atomics.docc/Extensions/ManagedAtomic.md b/Sources/Atomics/Atomics.docc/Extensions/ManagedAtomic.md index 3cffc71..c847351 100644 --- a/Sources/Atomics/Atomics.docc/Extensions/ManagedAtomic.md +++ b/Sources/Atomics/Atomics.docc/Extensions/ManagedAtomic.md @@ -13,6 +13,7 @@ - ``exchange(_:ordering:)`` - ``compareExchange(expected:desired:ordering:)`` - ``compareExchange(expected:desired:successOrdering:failureOrdering:)`` +- ``weakCompareExchange(expected:desired:ordering:)`` - ``weakCompareExchange(expected:desired:successOrdering:failureOrdering:)`` ### Atomic Integer Operations diff --git a/Sources/Atomics/Atomics.docc/Extensions/UnsafeAtomic.md b/Sources/Atomics/Atomics.docc/Extensions/UnsafeAtomic.md index fce2579..705a62e 100644 --- a/Sources/Atomics/Atomics.docc/Extensions/UnsafeAtomic.md +++ b/Sources/Atomics/Atomics.docc/Extensions/UnsafeAtomic.md @@ -22,6 +22,7 @@ - ``exchange(_:ordering:)`` - ``compareExchange(expected:desired:ordering:)`` - ``compareExchange(expected:desired:successOrdering:failureOrdering:)`` +- ``weakCompareExchange(expected:desired:ordering:)`` - ``weakCompareExchange(expected:desired:successOrdering:failureOrdering:)`` ### Atomic Integer Operations diff --git a/Sources/Atomics/CMakeLists.txt b/Sources/Atomics/CMakeLists.txt index a0c2818..e7cde36 100644 --- a/Sources/Atomics/CMakeLists.txt +++ b/Sources/Atomics/CMakeLists.txt @@ -31,6 +31,9 @@ add_library(Atomics set_target_properties(Atomics PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) +target_compile_options(Atomics PUBLIC + "$<$:SHELL:${ATOMICS_SWIFT_FLAGS}>" + "$<$:SHELL:${ATOMICS_C_FLAGS}>") if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") target_compile_options(Atomics PUBLIC "$<$:SHELL:-Xcc -mcx16>") diff --git a/Sources/Atomics/Conformances/AtomicBool.swift.gyb b/Sources/Atomics/Conformances/AtomicBool.swift.gyb index 7b74652..154ca6b 100644 --- a/Sources/Atomics/Conformances/AtomicBool.swift.gyb +++ b/Sources/Atomics/Conformances/AtomicBool.swift.gyb @@ -43,37 +43,55 @@ extension Bool: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Bool) { +#if ATOMICS_NATIVE_BUILTINS _storage = value._atomicRepresentation +#else + _storage = _sa_prepare_Int8(value._atomicRepresentation) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { +#if ATOMICS_NATIVE_BUILTINS return _storage._decodeBool +#else + return _sa_dispose_Int8(_storage)._decodeBool +#endif } } +} +#if ATOMICS_NATIVE_BUILTINS +extension Bool { @_transparent @_alwaysEmitIntoClient internal var _atomicRepresentation: _AtomicInt8Storage { let v: Int8 = (self ? 1 : 0) -#if ATOMICS_NATIVE_BUILTINS return .init(v._value) -#else - return _sa_prepare_Int8(v) -#endif } } extension _AtomicInt8Storage { @_transparent @_alwaysEmitIntoClient internal var _decodeBool: Bool { -#if ATOMICS_NATIVE_BUILTINS - return (Int8(self._value) & 1) != 0 + (Int8(self._value) & 1) != 0 + } +} #else - return (_sa_dispose_Int8(self) & 1) != 0 -#endif +extension Bool { + @_transparent @_alwaysEmitIntoClient + internal var _atomicRepresentation: Int8 { + self ? 1 : 0 } } +extension Int8 { + @_transparent @_alwaysEmitIntoClient + internal var _decodeBool: Bool { + (self & 1) != 0 + } +} +#endif + extension UnsafeMutablePointer where Pointee == Bool.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient diff --git a/Sources/Atomics/Conformances/IntegerConformances.swift.gyb b/Sources/Atomics/Conformances/IntegerConformances.swift.gyb index d2eb2a7..9c251a6 100644 --- a/Sources/Atomics/Conformances/IntegerConformances.swift.gyb +++ b/Sources/Atomics/Conformances/IntegerConformances.swift.gyb @@ -48,12 +48,20 @@ extension ${swiftType}: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_${shimType}(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_${shimType}(_storage)) +#endif } } } @@ -68,33 +76,39 @@ where Pointee == ${swiftType}.AtomicRepresentation { } } +#if ATOMICS_NATIVE_BUILTINS extension ${swiftType}.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS return Value(storage._value) + } + + @_transparent @_alwaysEmitIntoClient + static func _encode(_ value: Value) -> _Storage { + return _Storage(value._value) + } +} #else +extension ${swiftType}.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + static func _decode(_ v: ${shimType}) -> Value { % if swiftType == shimType: - return _sa_dispose_${shimType}(storage) + return v % else: - return Value(_sa_dispose_${shimType}(storage)._value) + return Value(v._value) % end -#endif } @_transparent @_alwaysEmitIntoClient - static func _encode(_ value: Value) -> _Storage { -#if ATOMICS_NATIVE_BUILTINS - return _Storage(value._value) -#else + static func _encode(_ value: Value) -> ${shimType} { % if swiftType == shimType: - return _sa_prepare_${shimType}(value) + return value % else: - return _sa_prepare_${shimType}(${shimType}(value._value)) + return ${shimType}(value._value) % end -#endif } } +#endif extension ${swiftType}.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") diff --git a/Sources/Atomics/Conformances/PointerConformances.swift.gyb b/Sources/Atomics/Conformances/PointerConformances.swift.gyb index fbc52ff..9a28231 100644 --- a/Sources/Atomics/Conformances/PointerConformances.swift.gyb +++ b/Sources/Atomics/Conformances/PointerConformances.swift.gyb @@ -41,12 +41,20 @@ extension ${swiftType}: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int(_storage)) +#endif } } } @@ -61,14 +69,13 @@ extension ${swiftType}.AtomicRepresentation { return UnsafeMutableRawPointer(ptr) .assumingMemoryBound(to: _Storage.self) } +} +#if ATOMICS_NATIVE_BUILTINS +extension ${swiftType}.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient internal static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS let bits = Int(storage._value) -#else - let bits = _sa_dispose_Int(storage) -#endif % if swiftType == "Unmanaged": return Unmanaged.fromOpaque(UnsafeRawPointer(bitPattern: bits)!) % else: @@ -83,13 +90,30 @@ extension ${swiftType}.AtomicRepresentation { % else: let bits = Int(bitPattern: value) % end -#if ATOMICS_NATIVE_BUILTINS return _Storage(bits._value) + } +} #else - return _sa_prepare_Int(bits) -#endif +extension ${swiftType}.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + internal static func _decode(_ bits: Int) -> Value { + % if swiftType == "Unmanaged": + return Unmanaged.fromOpaque(UnsafeRawPointer(bitPattern: bits)!) + % else: + return ${swiftType}(bitPattern: bits)! + % end + } + + @_transparent @_alwaysEmitIntoClient + internal static func _encode(_ value: Value) -> Int { + % if swiftType == "Unmanaged": + return Int(bitPattern: value.toOpaque()) + % else: + return Int(bitPattern: value) + % end } } +#endif extension ${swiftType}.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -189,12 +213,20 @@ extension ${swiftType}: AtomicOptionalWrappable { @inline(__always) @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int(Self._encode(value)) +#endif } @inline(__always) @_alwaysEmitIntoClient public func dispose() -> Value { +#if ATOMICS_NATIVE_BUILTINS Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int(_storage)) +#endif } } } @@ -209,14 +241,13 @@ extension ${swiftType}.AtomicOptionalRepresentation { return UnsafeMutableRawPointer(ptr) .assumingMemoryBound(to: _Storage.self) } +} +#if ATOMICS_NATIVE_BUILTINS +extension ${swiftType}.AtomicOptionalRepresentation { @_transparent @_alwaysEmitIntoClient internal static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS let bits = Int(storage._value) -#else - let bits = _sa_dispose_Int(storage) -#endif % if swiftType == "Unmanaged": guard let opaque = UnsafeRawPointer(bitPattern: bits) else { return nil @@ -234,13 +265,33 @@ extension ${swiftType}.AtomicOptionalRepresentation { % else: let bits = value.map { Int(bitPattern: $0) } ?? 0 % end -#if ATOMICS_NATIVE_BUILTINS return _Storage(bits._value) + } +} #else - return _sa_prepare_Int(bits) -#endif +extension ${swiftType}.AtomicOptionalRepresentation { + @_transparent @_alwaysEmitIntoClient + internal static func _decode(_ bits: Int) -> Value { + % if swiftType == "Unmanaged": + guard let opaque = UnsafeRawPointer(bitPattern: bits) else { + return nil + } + return Unmanaged.fromOpaque(opaque) + % else: + return ${swiftType}(bitPattern: bits) + % end + } + + @_transparent @_alwaysEmitIntoClient + internal static func _encode(_ value: Value) -> Int { + % if swiftType == "Unmanaged": + return value.map { Int(bitPattern: $0.toOpaque())} ?? 0 + % else: + return value.map { Int(bitPattern: $0) } ?? 0 + % end } } +#endif extension ${swiftType}.AtomicOptionalRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") diff --git a/Sources/Atomics/Conformances/autogenerated/AtomicBool.swift b/Sources/Atomics/Conformances/autogenerated/AtomicBool.swift index 6008f26..73b52e6 100644 --- a/Sources/Atomics/Conformances/autogenerated/AtomicBool.swift +++ b/Sources/Atomics/Conformances/autogenerated/AtomicBool.swift @@ -45,37 +45,55 @@ extension Bool: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Bool) { +#if ATOMICS_NATIVE_BUILTINS _storage = value._atomicRepresentation +#else + _storage = _sa_prepare_Int8(value._atomicRepresentation) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { +#if ATOMICS_NATIVE_BUILTINS return _storage._decodeBool +#else + return _sa_dispose_Int8(_storage)._decodeBool +#endif } } +} +#if ATOMICS_NATIVE_BUILTINS +extension Bool { @_transparent @_alwaysEmitIntoClient internal var _atomicRepresentation: _AtomicInt8Storage { let v: Int8 = (self ? 1 : 0) -#if ATOMICS_NATIVE_BUILTINS return .init(v._value) -#else - return _sa_prepare_Int8(v) -#endif } } extension _AtomicInt8Storage { @_transparent @_alwaysEmitIntoClient internal var _decodeBool: Bool { -#if ATOMICS_NATIVE_BUILTINS - return (Int8(self._value) & 1) != 0 + (Int8(self._value) & 1) != 0 + } +} #else - return (_sa_dispose_Int8(self) & 1) != 0 -#endif +extension Bool { + @_transparent @_alwaysEmitIntoClient + internal var _atomicRepresentation: Int8 { + self ? 1 : 0 } } +extension Int8 { + @_transparent @_alwaysEmitIntoClient + internal var _decodeBool: Bool { + (self & 1) != 0 + } +} +#endif + extension UnsafeMutablePointer where Pointee == Bool.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient diff --git a/Sources/Atomics/Conformances/autogenerated/IntegerConformances.swift b/Sources/Atomics/Conformances/autogenerated/IntegerConformances.swift index a53ac00..15a485f 100644 --- a/Sources/Atomics/Conformances/autogenerated/IntegerConformances.swift +++ b/Sources/Atomics/Conformances/autogenerated/IntegerConformances.swift @@ -35,12 +35,20 @@ extension Int8: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int8(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int8(_storage)) +#endif } } } @@ -55,25 +63,31 @@ where Pointee == Int8.AtomicRepresentation { } } +#if ATOMICS_NATIVE_BUILTINS extension Int8.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS return Value(storage._value) -#else - return _sa_dispose_Int8(storage) -#endif } @_transparent @_alwaysEmitIntoClient static func _encode(_ value: Value) -> _Storage { -#if ATOMICS_NATIVE_BUILTINS return _Storage(value._value) + } +} #else - return _sa_prepare_Int8(value) -#endif +extension Int8.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + static func _decode(_ v: Int8) -> Value { + return v + } + + @_transparent @_alwaysEmitIntoClient + static func _encode(_ value: Value) -> Int8 { + return value } } +#endif extension Int8.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -246,12 +260,20 @@ extension Int16: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int16(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int16(_storage)) +#endif } } } @@ -266,25 +288,31 @@ where Pointee == Int16.AtomicRepresentation { } } +#if ATOMICS_NATIVE_BUILTINS extension Int16.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS return Value(storage._value) -#else - return _sa_dispose_Int16(storage) -#endif } @_transparent @_alwaysEmitIntoClient static func _encode(_ value: Value) -> _Storage { -#if ATOMICS_NATIVE_BUILTINS return _Storage(value._value) + } +} #else - return _sa_prepare_Int16(value) -#endif +extension Int16.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + static func _decode(_ v: Int16) -> Value { + return v + } + + @_transparent @_alwaysEmitIntoClient + static func _encode(_ value: Value) -> Int16 { + return value } } +#endif extension Int16.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -457,12 +485,20 @@ extension Int32: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int32(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int32(_storage)) +#endif } } } @@ -477,25 +513,31 @@ where Pointee == Int32.AtomicRepresentation { } } +#if ATOMICS_NATIVE_BUILTINS extension Int32.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS return Value(storage._value) -#else - return _sa_dispose_Int32(storage) -#endif } @_transparent @_alwaysEmitIntoClient static func _encode(_ value: Value) -> _Storage { -#if ATOMICS_NATIVE_BUILTINS return _Storage(value._value) + } +} #else - return _sa_prepare_Int32(value) -#endif +extension Int32.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + static func _decode(_ v: Int32) -> Value { + return v + } + + @_transparent @_alwaysEmitIntoClient + static func _encode(_ value: Value) -> Int32 { + return value } } +#endif extension Int32.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -668,12 +710,20 @@ extension Int64: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int64(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int64(_storage)) +#endif } } } @@ -688,25 +738,31 @@ where Pointee == Int64.AtomicRepresentation { } } +#if ATOMICS_NATIVE_BUILTINS extension Int64.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS return Value(storage._value) -#else - return _sa_dispose_Int64(storage) -#endif } @_transparent @_alwaysEmitIntoClient static func _encode(_ value: Value) -> _Storage { -#if ATOMICS_NATIVE_BUILTINS return _Storage(value._value) + } +} #else - return _sa_prepare_Int64(value) -#endif +extension Int64.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + static func _decode(_ v: Int64) -> Value { + return v + } + + @_transparent @_alwaysEmitIntoClient + static func _encode(_ value: Value) -> Int64 { + return value } } +#endif extension Int64.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -879,12 +935,20 @@ extension UInt8: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int8(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int8(_storage)) +#endif } } } @@ -899,25 +963,31 @@ where Pointee == UInt8.AtomicRepresentation { } } +#if ATOMICS_NATIVE_BUILTINS extension UInt8.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS return Value(storage._value) -#else - return Value(_sa_dispose_Int8(storage)._value) -#endif } @_transparent @_alwaysEmitIntoClient static func _encode(_ value: Value) -> _Storage { -#if ATOMICS_NATIVE_BUILTINS return _Storage(value._value) + } +} #else - return _sa_prepare_Int8(Int8(value._value)) -#endif +extension UInt8.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + static func _decode(_ v: Int8) -> Value { + return Value(v._value) + } + + @_transparent @_alwaysEmitIntoClient + static func _encode(_ value: Value) -> Int8 { + return Int8(value._value) } } +#endif extension UInt8.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -1090,12 +1160,20 @@ extension UInt16: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int16(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int16(_storage)) +#endif } } } @@ -1110,25 +1188,31 @@ where Pointee == UInt16.AtomicRepresentation { } } +#if ATOMICS_NATIVE_BUILTINS extension UInt16.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS return Value(storage._value) -#else - return Value(_sa_dispose_Int16(storage)._value) -#endif } @_transparent @_alwaysEmitIntoClient static func _encode(_ value: Value) -> _Storage { -#if ATOMICS_NATIVE_BUILTINS return _Storage(value._value) + } +} #else - return _sa_prepare_Int16(Int16(value._value)) -#endif +extension UInt16.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + static func _decode(_ v: Int16) -> Value { + return Value(v._value) + } + + @_transparent @_alwaysEmitIntoClient + static func _encode(_ value: Value) -> Int16 { + return Int16(value._value) } } +#endif extension UInt16.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -1301,12 +1385,20 @@ extension UInt32: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int32(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int32(_storage)) +#endif } } } @@ -1321,25 +1413,31 @@ where Pointee == UInt32.AtomicRepresentation { } } +#if ATOMICS_NATIVE_BUILTINS extension UInt32.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS return Value(storage._value) -#else - return Value(_sa_dispose_Int32(storage)._value) -#endif } @_transparent @_alwaysEmitIntoClient static func _encode(_ value: Value) -> _Storage { -#if ATOMICS_NATIVE_BUILTINS return _Storage(value._value) + } +} #else - return _sa_prepare_Int32(Int32(value._value)) -#endif +extension UInt32.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + static func _decode(_ v: Int32) -> Value { + return Value(v._value) + } + + @_transparent @_alwaysEmitIntoClient + static func _encode(_ value: Value) -> Int32 { + return Int32(value._value) } } +#endif extension UInt32.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -1512,12 +1610,20 @@ extension UInt64: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int64(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int64(_storage)) +#endif } } } @@ -1532,25 +1638,31 @@ where Pointee == UInt64.AtomicRepresentation { } } +#if ATOMICS_NATIVE_BUILTINS extension UInt64.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS return Value(storage._value) -#else - return Value(_sa_dispose_Int64(storage)._value) -#endif } @_transparent @_alwaysEmitIntoClient static func _encode(_ value: Value) -> _Storage { -#if ATOMICS_NATIVE_BUILTINS return _Storage(value._value) + } +} #else - return _sa_prepare_Int64(Int64(value._value)) -#endif +extension UInt64.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + static func _decode(_ v: Int64) -> Value { + return Value(v._value) + } + + @_transparent @_alwaysEmitIntoClient + static func _encode(_ value: Value) -> Int64 { + return Int64(value._value) } } +#endif extension UInt64.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -1723,12 +1835,20 @@ extension Int: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int(_storage)) +#endif } } } @@ -1743,25 +1863,31 @@ where Pointee == Int.AtomicRepresentation { } } +#if ATOMICS_NATIVE_BUILTINS extension Int.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS return Value(storage._value) -#else - return _sa_dispose_Int(storage) -#endif } @_transparent @_alwaysEmitIntoClient static func _encode(_ value: Value) -> _Storage { -#if ATOMICS_NATIVE_BUILTINS return _Storage(value._value) + } +} #else - return _sa_prepare_Int(value) -#endif +extension Int.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + static func _decode(_ v: Int) -> Value { + return v + } + + @_transparent @_alwaysEmitIntoClient + static func _encode(_ value: Value) -> Int { + return value } } +#endif extension Int.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -1934,12 +2060,20 @@ extension UInt: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int(_storage)) +#endif } } } @@ -1954,25 +2088,31 @@ where Pointee == UInt.AtomicRepresentation { } } +#if ATOMICS_NATIVE_BUILTINS extension UInt.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS return Value(storage._value) -#else - return Value(_sa_dispose_Int(storage)._value) -#endif } @_transparent @_alwaysEmitIntoClient static func _encode(_ value: Value) -> _Storage { -#if ATOMICS_NATIVE_BUILTINS return _Storage(value._value) + } +} #else - return _sa_prepare_Int(Int(value._value)) -#endif +extension UInt.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + static func _decode(_ v: Int) -> Value { + return Value(v._value) + } + + @_transparent @_alwaysEmitIntoClient + static func _encode(_ value: Value) -> Int { + return Int(value._value) } } +#endif extension UInt.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -2145,12 +2285,20 @@ extension DoubleWord: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_DoubleWord(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_DoubleWord(_storage)) +#endif } } } @@ -2165,25 +2313,31 @@ where Pointee == DoubleWord.AtomicRepresentation { } } +#if ATOMICS_NATIVE_BUILTINS extension DoubleWord.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS return Value(storage._value) -#else - return _sa_dispose_DoubleWord(storage) -#endif } @_transparent @_alwaysEmitIntoClient static func _encode(_ value: Value) -> _Storage { -#if ATOMICS_NATIVE_BUILTINS return _Storage(value._value) + } +} #else - return _sa_prepare_DoubleWord(value) -#endif +extension DoubleWord.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + static func _decode(_ v: DoubleWord) -> Value { + return v + } + + @_transparent @_alwaysEmitIntoClient + static func _encode(_ value: Value) -> DoubleWord { + return value } } +#endif extension DoubleWord.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") diff --git a/Sources/Atomics/Conformances/autogenerated/PointerConformances.swift b/Sources/Atomics/Conformances/autogenerated/PointerConformances.swift index f9bd61d..415fa27 100644 --- a/Sources/Atomics/Conformances/autogenerated/PointerConformances.swift +++ b/Sources/Atomics/Conformances/autogenerated/PointerConformances.swift @@ -35,12 +35,20 @@ extension UnsafeRawPointer: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int(_storage)) +#endif } } } @@ -55,27 +63,35 @@ extension UnsafeRawPointer.AtomicRepresentation { return UnsafeMutableRawPointer(ptr) .assumingMemoryBound(to: _Storage.self) } +} +#if ATOMICS_NATIVE_BUILTINS +extension UnsafeRawPointer.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient internal static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS let bits = Int(storage._value) -#else - let bits = _sa_dispose_Int(storage) -#endif return UnsafeRawPointer(bitPattern: bits)! } @_transparent @_alwaysEmitIntoClient internal static func _encode(_ value: Value) -> _Storage { let bits = Int(bitPattern: value) -#if ATOMICS_NATIVE_BUILTINS return _Storage(bits._value) + } +} #else - return _sa_prepare_Int(bits) -#endif +extension UnsafeRawPointer.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + internal static func _decode(_ bits: Int) -> Value { + return UnsafeRawPointer(bitPattern: bits)! + } + + @_transparent @_alwaysEmitIntoClient + internal static func _encode(_ value: Value) -> Int { + return Int(bitPattern: value) } } +#endif extension UnsafeRawPointer.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -171,12 +187,20 @@ extension UnsafeMutableRawPointer: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int(_storage)) +#endif } } } @@ -191,27 +215,35 @@ extension UnsafeMutableRawPointer.AtomicRepresentation { return UnsafeMutableRawPointer(ptr) .assumingMemoryBound(to: _Storage.self) } +} +#if ATOMICS_NATIVE_BUILTINS +extension UnsafeMutableRawPointer.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient internal static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS let bits = Int(storage._value) -#else - let bits = _sa_dispose_Int(storage) -#endif return UnsafeMutableRawPointer(bitPattern: bits)! } @_transparent @_alwaysEmitIntoClient internal static func _encode(_ value: Value) -> _Storage { let bits = Int(bitPattern: value) -#if ATOMICS_NATIVE_BUILTINS return _Storage(bits._value) + } +} #else - return _sa_prepare_Int(bits) -#endif +extension UnsafeMutableRawPointer.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + internal static func _decode(_ bits: Int) -> Value { + return UnsafeMutableRawPointer(bitPattern: bits)! + } + + @_transparent @_alwaysEmitIntoClient + internal static func _encode(_ value: Value) -> Int { + return Int(bitPattern: value) } } +#endif extension UnsafeMutableRawPointer.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -307,12 +339,20 @@ extension UnsafePointer: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int(_storage)) +#endif } } } @@ -327,27 +367,35 @@ extension UnsafePointer.AtomicRepresentation { return UnsafeMutableRawPointer(ptr) .assumingMemoryBound(to: _Storage.self) } +} +#if ATOMICS_NATIVE_BUILTINS +extension UnsafePointer.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient internal static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS let bits = Int(storage._value) -#else - let bits = _sa_dispose_Int(storage) -#endif return UnsafePointer(bitPattern: bits)! } @_transparent @_alwaysEmitIntoClient internal static func _encode(_ value: Value) -> _Storage { let bits = Int(bitPattern: value) -#if ATOMICS_NATIVE_BUILTINS return _Storage(bits._value) + } +} #else - return _sa_prepare_Int(bits) -#endif +extension UnsafePointer.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + internal static func _decode(_ bits: Int) -> Value { + return UnsafePointer(bitPattern: bits)! + } + + @_transparent @_alwaysEmitIntoClient + internal static func _encode(_ value: Value) -> Int { + return Int(bitPattern: value) } } +#endif extension UnsafePointer.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -443,12 +491,20 @@ extension UnsafeMutablePointer: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int(_storage)) +#endif } } } @@ -463,27 +519,35 @@ extension UnsafeMutablePointer.AtomicRepresentation { return UnsafeMutableRawPointer(ptr) .assumingMemoryBound(to: _Storage.self) } +} +#if ATOMICS_NATIVE_BUILTINS +extension UnsafeMutablePointer.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient internal static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS let bits = Int(storage._value) -#else - let bits = _sa_dispose_Int(storage) -#endif return UnsafeMutablePointer(bitPattern: bits)! } @_transparent @_alwaysEmitIntoClient internal static func _encode(_ value: Value) -> _Storage { let bits = Int(bitPattern: value) -#if ATOMICS_NATIVE_BUILTINS return _Storage(bits._value) + } +} #else - return _sa_prepare_Int(bits) -#endif +extension UnsafeMutablePointer.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + internal static func _decode(_ bits: Int) -> Value { + return UnsafeMutablePointer(bitPattern: bits)! + } + + @_transparent @_alwaysEmitIntoClient + internal static func _encode(_ value: Value) -> Int { + return Int(bitPattern: value) } } +#endif extension UnsafeMutablePointer.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -579,12 +643,20 @@ extension Unmanaged: AtomicValue { @_transparent @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int(Self._encode(value)) +#endif } @_transparent @_alwaysEmitIntoClient public func dispose() -> Value { - Self._decode(_storage) +#if ATOMICS_NATIVE_BUILTINS + return Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int(_storage)) +#endif } } } @@ -599,27 +671,35 @@ extension Unmanaged.AtomicRepresentation { return UnsafeMutableRawPointer(ptr) .assumingMemoryBound(to: _Storage.self) } +} +#if ATOMICS_NATIVE_BUILTINS +extension Unmanaged.AtomicRepresentation { @_transparent @_alwaysEmitIntoClient internal static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS let bits = Int(storage._value) -#else - let bits = _sa_dispose_Int(storage) -#endif return Unmanaged.fromOpaque(UnsafeRawPointer(bitPattern: bits)!) } @_transparent @_alwaysEmitIntoClient internal static func _encode(_ value: Value) -> _Storage { let bits = Int(bitPattern: value.toOpaque()) -#if ATOMICS_NATIVE_BUILTINS return _Storage(bits._value) + } +} #else - return _sa_prepare_Int(bits) -#endif +extension Unmanaged.AtomicRepresentation { + @_transparent @_alwaysEmitIntoClient + internal static func _decode(_ bits: Int) -> Value { + return Unmanaged.fromOpaque(UnsafeRawPointer(bitPattern: bits)!) + } + + @_transparent @_alwaysEmitIntoClient + internal static func _encode(_ value: Value) -> Int { + return Int(bitPattern: value.toOpaque()) } } +#endif extension Unmanaged.AtomicRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -717,12 +797,20 @@ extension UnsafeRawPointer: AtomicOptionalWrappable { @inline(__always) @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int(Self._encode(value)) +#endif } @inline(__always) @_alwaysEmitIntoClient public func dispose() -> Value { +#if ATOMICS_NATIVE_BUILTINS Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int(_storage)) +#endif } } } @@ -737,27 +825,35 @@ extension UnsafeRawPointer.AtomicOptionalRepresentation { return UnsafeMutableRawPointer(ptr) .assumingMemoryBound(to: _Storage.self) } +} +#if ATOMICS_NATIVE_BUILTINS +extension UnsafeRawPointer.AtomicOptionalRepresentation { @_transparent @_alwaysEmitIntoClient internal static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS let bits = Int(storage._value) -#else - let bits = _sa_dispose_Int(storage) -#endif return UnsafeRawPointer(bitPattern: bits) } @_transparent @_alwaysEmitIntoClient internal static func _encode(_ value: Value) -> _Storage { let bits = value.map { Int(bitPattern: $0) } ?? 0 -#if ATOMICS_NATIVE_BUILTINS return _Storage(bits._value) + } +} #else - return _sa_prepare_Int(bits) -#endif +extension UnsafeRawPointer.AtomicOptionalRepresentation { + @_transparent @_alwaysEmitIntoClient + internal static func _decode(_ bits: Int) -> Value { + return UnsafeRawPointer(bitPattern: bits) + } + + @_transparent @_alwaysEmitIntoClient + internal static func _encode(_ value: Value) -> Int { + return value.map { Int(bitPattern: $0) } ?? 0 } } +#endif extension UnsafeRawPointer.AtomicOptionalRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -851,12 +947,20 @@ extension UnsafeMutableRawPointer: AtomicOptionalWrappable { @inline(__always) @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int(Self._encode(value)) +#endif } @inline(__always) @_alwaysEmitIntoClient public func dispose() -> Value { +#if ATOMICS_NATIVE_BUILTINS Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int(_storage)) +#endif } } } @@ -871,27 +975,35 @@ extension UnsafeMutableRawPointer.AtomicOptionalRepresentation { return UnsafeMutableRawPointer(ptr) .assumingMemoryBound(to: _Storage.self) } +} +#if ATOMICS_NATIVE_BUILTINS +extension UnsafeMutableRawPointer.AtomicOptionalRepresentation { @_transparent @_alwaysEmitIntoClient internal static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS let bits = Int(storage._value) -#else - let bits = _sa_dispose_Int(storage) -#endif return UnsafeMutableRawPointer(bitPattern: bits) } @_transparent @_alwaysEmitIntoClient internal static func _encode(_ value: Value) -> _Storage { let bits = value.map { Int(bitPattern: $0) } ?? 0 -#if ATOMICS_NATIVE_BUILTINS return _Storage(bits._value) + } +} #else - return _sa_prepare_Int(bits) -#endif +extension UnsafeMutableRawPointer.AtomicOptionalRepresentation { + @_transparent @_alwaysEmitIntoClient + internal static func _decode(_ bits: Int) -> Value { + return UnsafeMutableRawPointer(bitPattern: bits) + } + + @_transparent @_alwaysEmitIntoClient + internal static func _encode(_ value: Value) -> Int { + return value.map { Int(bitPattern: $0) } ?? 0 } } +#endif extension UnsafeMutableRawPointer.AtomicOptionalRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -985,12 +1097,20 @@ extension UnsafePointer: AtomicOptionalWrappable { @inline(__always) @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int(Self._encode(value)) +#endif } @inline(__always) @_alwaysEmitIntoClient public func dispose() -> Value { +#if ATOMICS_NATIVE_BUILTINS Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int(_storage)) +#endif } } } @@ -1005,27 +1125,35 @@ extension UnsafePointer.AtomicOptionalRepresentation { return UnsafeMutableRawPointer(ptr) .assumingMemoryBound(to: _Storage.self) } +} +#if ATOMICS_NATIVE_BUILTINS +extension UnsafePointer.AtomicOptionalRepresentation { @_transparent @_alwaysEmitIntoClient internal static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS let bits = Int(storage._value) -#else - let bits = _sa_dispose_Int(storage) -#endif return UnsafePointer(bitPattern: bits) } @_transparent @_alwaysEmitIntoClient internal static func _encode(_ value: Value) -> _Storage { let bits = value.map { Int(bitPattern: $0) } ?? 0 -#if ATOMICS_NATIVE_BUILTINS return _Storage(bits._value) + } +} #else - return _sa_prepare_Int(bits) -#endif +extension UnsafePointer.AtomicOptionalRepresentation { + @_transparent @_alwaysEmitIntoClient + internal static func _decode(_ bits: Int) -> Value { + return UnsafePointer(bitPattern: bits) + } + + @_transparent @_alwaysEmitIntoClient + internal static func _encode(_ value: Value) -> Int { + return value.map { Int(bitPattern: $0) } ?? 0 } } +#endif extension UnsafePointer.AtomicOptionalRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -1119,12 +1247,20 @@ extension UnsafeMutablePointer: AtomicOptionalWrappable { @inline(__always) @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int(Self._encode(value)) +#endif } @inline(__always) @_alwaysEmitIntoClient public func dispose() -> Value { +#if ATOMICS_NATIVE_BUILTINS Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int(_storage)) +#endif } } } @@ -1139,27 +1275,35 @@ extension UnsafeMutablePointer.AtomicOptionalRepresentation { return UnsafeMutableRawPointer(ptr) .assumingMemoryBound(to: _Storage.self) } +} +#if ATOMICS_NATIVE_BUILTINS +extension UnsafeMutablePointer.AtomicOptionalRepresentation { @_transparent @_alwaysEmitIntoClient internal static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS let bits = Int(storage._value) -#else - let bits = _sa_dispose_Int(storage) -#endif return UnsafeMutablePointer(bitPattern: bits) } @_transparent @_alwaysEmitIntoClient internal static func _encode(_ value: Value) -> _Storage { let bits = value.map { Int(bitPattern: $0) } ?? 0 -#if ATOMICS_NATIVE_BUILTINS return _Storage(bits._value) + } +} #else - return _sa_prepare_Int(bits) -#endif +extension UnsafeMutablePointer.AtomicOptionalRepresentation { + @_transparent @_alwaysEmitIntoClient + internal static func _decode(_ bits: Int) -> Value { + return UnsafeMutablePointer(bitPattern: bits) + } + + @_transparent @_alwaysEmitIntoClient + internal static func _encode(_ value: Value) -> Int { + return value.map { Int(bitPattern: $0) } ?? 0 } } +#endif extension UnsafeMutablePointer.AtomicOptionalRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") @@ -1253,12 +1397,20 @@ extension Unmanaged: AtomicOptionalWrappable { @inline(__always) @_alwaysEmitIntoClient public init(_ value: Value) { +#if ATOMICS_NATIVE_BUILTINS _storage = Self._encode(value) +#else + _storage = _sa_prepare_Int(Self._encode(value)) +#endif } @inline(__always) @_alwaysEmitIntoClient public func dispose() -> Value { +#if ATOMICS_NATIVE_BUILTINS Self._decode(_storage) +#else + return Self._decode(_sa_dispose_Int(_storage)) +#endif } } } @@ -1273,14 +1425,13 @@ extension Unmanaged.AtomicOptionalRepresentation { return UnsafeMutableRawPointer(ptr) .assumingMemoryBound(to: _Storage.self) } +} +#if ATOMICS_NATIVE_BUILTINS +extension Unmanaged.AtomicOptionalRepresentation { @_transparent @_alwaysEmitIntoClient internal static func _decode(_ storage: _Storage) -> Value { -#if ATOMICS_NATIVE_BUILTINS let bits = Int(storage._value) -#else - let bits = _sa_dispose_Int(storage) -#endif guard let opaque = UnsafeRawPointer(bitPattern: bits) else { return nil } @@ -1290,13 +1441,25 @@ extension Unmanaged.AtomicOptionalRepresentation { @_transparent @_alwaysEmitIntoClient internal static func _encode(_ value: Value) -> _Storage { let bits = value.map { Int(bitPattern: $0.toOpaque())} ?? 0 -#if ATOMICS_NATIVE_BUILTINS return _Storage(bits._value) + } +} #else - return _sa_prepare_Int(bits) -#endif +extension Unmanaged.AtomicOptionalRepresentation { + @_transparent @_alwaysEmitIntoClient + internal static func _decode(_ bits: Int) -> Value { + guard let opaque = UnsafeRawPointer(bitPattern: bits) else { + return nil + } + return Unmanaged.fromOpaque(opaque) + } + + @_transparent @_alwaysEmitIntoClient + internal static func _encode(_ value: Value) -> Int { + return value.map { Int(bitPattern: $0.toOpaque())} ?? 0 } } +#endif extension Unmanaged.AtomicOptionalRepresentation: AtomicStorage { @_semantics("atomics.requires_constant_orderings") diff --git a/Sources/Atomics/Primitives/Primitives.native.swift.gyb b/Sources/Atomics/Primitives/Primitives.native.swift.gyb index 0709186..bfa9657 100644 --- a/Sources/Atomics/Primitives/Primitives.native.swift.gyb +++ b/Sources/Atomics/Primitives/Primitives.native.swift.gyb @@ -15,7 +15,13 @@ }% ${autogenerated_warning()} -#if ATOMICS_NATIVE_BUILTINS +// FIXME: The conditionals below have been carefully constructed to +// avoid confusing Swift 5.7; they can be sanitized once we drop support +// for that version. +#if compiler(>=5.9) +#if !ATOMICS_NATIVE_BUILTINS +#error("swift-atomics requires native builtins on Swift 5.9") +#endif import Builtin @_alwaysEmitIntoClient @@ -277,4 +283,8 @@ extension UnsafeMutablePointer where Pointee == ${swiftType} { #error("Unexpected pointer bit width") #endif -#endif // ATOMICS_NATIVE_BUILTINS +#else // compiler(>=5.9) +#if ATOMICS_NATIVE_BUILTINS +#error("swift-atomics requires C shims on Swift versions below 5.9") +#endif +#endif // compiler(>=5.9) diff --git a/Sources/Atomics/Primitives/Primitives.shims.swift.gyb b/Sources/Atomics/Primitives/Primitives.shims.swift.gyb index b7d0546..cdd8b7a 100644 --- a/Sources/Atomics/Primitives/Primitives.shims.swift.gyb +++ b/Sources/Atomics/Primitives/Primitives.shims.swift.gyb @@ -45,7 +45,7 @@ extension UnsafeMutablePointer where Pointee == ${storageType} { @_alwaysEmitIntoClient @_transparent // Debug performance @usableFromInline - internal func _atomicLoad(ordering: AtomicLoadOrdering) -> ${storageType} { + internal func _atomicLoad(ordering: AtomicLoadOrdering) -> ${valueType} { switch ordering { % for (enumOrder, apiOrder, docOrder, llvmOrder) in loadOrderings: case .${enumOrder}: @@ -63,7 +63,7 @@ extension UnsafeMutablePointer where Pointee == ${storageType} { @_transparent // Debug performance @usableFromInline internal func _atomicStore( - _ desired: ${storageType}, + _ desired: ${valueType}, ordering: AtomicStoreOrdering ) { switch ordering { @@ -82,9 +82,9 @@ extension UnsafeMutablePointer where Pointee == ${storageType} { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicExchange( - _ desired: ${storageType}, + _ desired: ${valueType}, ordering: AtomicUpdateOrdering - ) -> ${storageType} { + ) -> ${valueType} { switch ordering { % for (enumOrder, apiOrder, docOrder, llvmOrder, failOrder) in updateOrderings: case .${enumOrder}: @@ -112,10 +112,10 @@ extension UnsafeMutablePointer where Pointee == ${storageType} { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicCompareExchange( - expected: ${storageType}, - desired: ${storageType}, + expected: ${valueType}, + desired: ${valueType}, ordering: AtomicUpdateOrdering - ) -> (exchanged: Bool, original: ${storageType}) { + ) -> (exchanged: Bool, original: ${valueType}) { var expected = expected let exchanged: Bool switch ordering { @@ -151,11 +151,11 @@ extension UnsafeMutablePointer where Pointee == ${storageType} { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicCompareExchange( - expected: ${storageType}, - desired: ${storageType}, + expected: ${valueType}, + desired: ${valueType}, successOrdering: AtomicUpdateOrdering, failureOrdering: AtomicLoadOrdering - ) -> (exchanged: Bool, original: ${storageType}) { + ) -> (exchanged: Bool, original: ${valueType}) { // FIXME: LLVM doesn't support arbitrary ordering combinations // yet, so upgrade the success ordering when necessary so that it // is at least as "strong" as the failure case. @@ -196,11 +196,11 @@ extension UnsafeMutablePointer where Pointee == ${storageType} { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicWeakCompareExchange( - expected: ${storageType}, - desired: ${storageType}, + expected: ${valueType}, + desired: ${valueType}, successOrdering: AtomicUpdateOrdering, failureOrdering: AtomicLoadOrdering - ) -> (exchanged: Bool, original: ${storageType}) { + ) -> (exchanged: Bool, original: ${valueType}) { // FIXME: LLVM doesn't support arbitrary ordering combinations // yet, so upgrade the success ordering when necessary so that it // is at least as "strong" as the failure case. @@ -237,9 +237,9 @@ extension UnsafeMutablePointer where Pointee == ${storageType} { @usableFromInline internal func _atomicLoadThen${swiftName}( - ${label} operand: ${storageType}, + ${label} operand: ${valueType}, ordering: AtomicUpdateOrdering - ) -> ${storageType} { + ) -> ${valueType} { switch ordering { % for (enumOrder, apiOrder, docOrder, llvmOrder, failOrder) in updateOrderings: case .${enumOrder}: diff --git a/Sources/Atomics/Primitives/autogenerated/Primitives.native.swift b/Sources/Atomics/Primitives/autogenerated/Primitives.native.swift index 663f1bf..99b728c 100644 --- a/Sources/Atomics/Primitives/autogenerated/Primitives.native.swift +++ b/Sources/Atomics/Primitives/autogenerated/Primitives.native.swift @@ -18,7 +18,13 @@ // ############################################################################# -#if ATOMICS_NATIVE_BUILTINS +// FIXME: The conditionals below have been carefully constructed to +// avoid confusing Swift 5.7; they can be sanitized once we drop support +// for that version. +#if compiler(>=5.9) +#if !ATOMICS_NATIVE_BUILTINS +#error("swift-atomics requires native builtins on Swift 5.9") +#endif import Builtin @_alwaysEmitIntoClient @@ -2448,4 +2454,8 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt128Storage { #error("Unexpected pointer bit width") #endif -#endif // ATOMICS_NATIVE_BUILTINS +#else // compiler(>=5.9) +#if ATOMICS_NATIVE_BUILTINS +#error("swift-atomics requires C shims on Swift versions below 5.9") +#endif +#endif // compiler(>=5.9) diff --git a/Sources/Atomics/Primitives/autogenerated/Primitives.shims.swift b/Sources/Atomics/Primitives/autogenerated/Primitives.shims.swift index ee34c0d..ced9b3b 100644 --- a/Sources/Atomics/Primitives/autogenerated/Primitives.shims.swift +++ b/Sources/Atomics/Primitives/autogenerated/Primitives.shims.swift @@ -49,7 +49,7 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt8Storage { @_alwaysEmitIntoClient @_transparent // Debug performance @usableFromInline - internal func _atomicLoad(ordering: AtomicLoadOrdering) -> _AtomicInt8Storage { + internal func _atomicLoad(ordering: AtomicLoadOrdering) -> Int8 { switch ordering { case .relaxed: return _sa_load_relaxed_Int8(self) @@ -69,7 +69,7 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt8Storage { @_transparent // Debug performance @usableFromInline internal func _atomicStore( - _ desired: _AtomicInt8Storage, + _ desired: Int8, ordering: AtomicStoreOrdering ) { switch ordering { @@ -90,9 +90,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt8Storage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicExchange( - _ desired: _AtomicInt8Storage, + _ desired: Int8, ordering: AtomicUpdateOrdering - ) -> _AtomicInt8Storage { + ) -> Int8 { switch ordering { case .relaxed: return _sa_exchange_relaxed_Int8(self, desired) @@ -126,10 +126,10 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt8Storage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicCompareExchange( - expected: _AtomicInt8Storage, - desired: _AtomicInt8Storage, + expected: Int8, + desired: Int8, ordering: AtomicUpdateOrdering - ) -> (exchanged: Bool, original: _AtomicInt8Storage) { + ) -> (exchanged: Bool, original: Int8) { var expected = expected let exchanged: Bool switch ordering { @@ -175,11 +175,11 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt8Storage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicCompareExchange( - expected: _AtomicInt8Storage, - desired: _AtomicInt8Storage, + expected: Int8, + desired: Int8, successOrdering: AtomicUpdateOrdering, failureOrdering: AtomicLoadOrdering - ) -> (exchanged: Bool, original: _AtomicInt8Storage) { + ) -> (exchanged: Bool, original: Int8) { // FIXME: LLVM doesn't support arbitrary ordering combinations // yet, so upgrade the success ordering when necessary so that it // is at least as "strong" as the failure case. @@ -258,11 +258,11 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt8Storage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicWeakCompareExchange( - expected: _AtomicInt8Storage, - desired: _AtomicInt8Storage, + expected: Int8, + desired: Int8, successOrdering: AtomicUpdateOrdering, failureOrdering: AtomicLoadOrdering - ) -> (exchanged: Bool, original: _AtomicInt8Storage) { + ) -> (exchanged: Bool, original: Int8) { // FIXME: LLVM doesn't support arbitrary ordering combinations // yet, so upgrade the success ordering when necessary so that it // is at least as "strong" as the failure case. @@ -333,9 +333,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt8Storage { @usableFromInline internal func _atomicLoadThenWrappingIncrement( - by operand: _AtomicInt8Storage, + by operand: Int8, ordering: AtomicUpdateOrdering - ) -> _AtomicInt8Storage { + ) -> Int8 { switch ordering { case .relaxed: return _sa_fetch_add_relaxed_Int8( @@ -369,9 +369,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt8Storage { @usableFromInline internal func _atomicLoadThenWrappingDecrement( - by operand: _AtomicInt8Storage, + by operand: Int8, ordering: AtomicUpdateOrdering - ) -> _AtomicInt8Storage { + ) -> Int8 { switch ordering { case .relaxed: return _sa_fetch_sub_relaxed_Int8( @@ -402,9 +402,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt8Storage { @usableFromInline internal func _atomicLoadThenBitwiseAnd( - with operand: _AtomicInt8Storage, + with operand: Int8, ordering: AtomicUpdateOrdering - ) -> _AtomicInt8Storage { + ) -> Int8 { switch ordering { case .relaxed: return _sa_fetch_and_relaxed_Int8( @@ -435,9 +435,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt8Storage { @usableFromInline internal func _atomicLoadThenBitwiseOr( - with operand: _AtomicInt8Storage, + with operand: Int8, ordering: AtomicUpdateOrdering - ) -> _AtomicInt8Storage { + ) -> Int8 { switch ordering { case .relaxed: return _sa_fetch_or_relaxed_Int8( @@ -468,9 +468,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt8Storage { @usableFromInline internal func _atomicLoadThenBitwiseXor( - with operand: _AtomicInt8Storage, + with operand: Int8, ordering: AtomicUpdateOrdering - ) -> _AtomicInt8Storage { + ) -> Int8 { switch ordering { case .relaxed: return _sa_fetch_xor_relaxed_Int8( @@ -499,7 +499,7 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt16Storage { @_alwaysEmitIntoClient @_transparent // Debug performance @usableFromInline - internal func _atomicLoad(ordering: AtomicLoadOrdering) -> _AtomicInt16Storage { + internal func _atomicLoad(ordering: AtomicLoadOrdering) -> Int16 { switch ordering { case .relaxed: return _sa_load_relaxed_Int16(self) @@ -519,7 +519,7 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt16Storage { @_transparent // Debug performance @usableFromInline internal func _atomicStore( - _ desired: _AtomicInt16Storage, + _ desired: Int16, ordering: AtomicStoreOrdering ) { switch ordering { @@ -540,9 +540,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt16Storage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicExchange( - _ desired: _AtomicInt16Storage, + _ desired: Int16, ordering: AtomicUpdateOrdering - ) -> _AtomicInt16Storage { + ) -> Int16 { switch ordering { case .relaxed: return _sa_exchange_relaxed_Int16(self, desired) @@ -576,10 +576,10 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt16Storage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicCompareExchange( - expected: _AtomicInt16Storage, - desired: _AtomicInt16Storage, + expected: Int16, + desired: Int16, ordering: AtomicUpdateOrdering - ) -> (exchanged: Bool, original: _AtomicInt16Storage) { + ) -> (exchanged: Bool, original: Int16) { var expected = expected let exchanged: Bool switch ordering { @@ -625,11 +625,11 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt16Storage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicCompareExchange( - expected: _AtomicInt16Storage, - desired: _AtomicInt16Storage, + expected: Int16, + desired: Int16, successOrdering: AtomicUpdateOrdering, failureOrdering: AtomicLoadOrdering - ) -> (exchanged: Bool, original: _AtomicInt16Storage) { + ) -> (exchanged: Bool, original: Int16) { // FIXME: LLVM doesn't support arbitrary ordering combinations // yet, so upgrade the success ordering when necessary so that it // is at least as "strong" as the failure case. @@ -708,11 +708,11 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt16Storage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicWeakCompareExchange( - expected: _AtomicInt16Storage, - desired: _AtomicInt16Storage, + expected: Int16, + desired: Int16, successOrdering: AtomicUpdateOrdering, failureOrdering: AtomicLoadOrdering - ) -> (exchanged: Bool, original: _AtomicInt16Storage) { + ) -> (exchanged: Bool, original: Int16) { // FIXME: LLVM doesn't support arbitrary ordering combinations // yet, so upgrade the success ordering when necessary so that it // is at least as "strong" as the failure case. @@ -783,9 +783,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt16Storage { @usableFromInline internal func _atomicLoadThenWrappingIncrement( - by operand: _AtomicInt16Storage, + by operand: Int16, ordering: AtomicUpdateOrdering - ) -> _AtomicInt16Storage { + ) -> Int16 { switch ordering { case .relaxed: return _sa_fetch_add_relaxed_Int16( @@ -819,9 +819,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt16Storage { @usableFromInline internal func _atomicLoadThenWrappingDecrement( - by operand: _AtomicInt16Storage, + by operand: Int16, ordering: AtomicUpdateOrdering - ) -> _AtomicInt16Storage { + ) -> Int16 { switch ordering { case .relaxed: return _sa_fetch_sub_relaxed_Int16( @@ -852,9 +852,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt16Storage { @usableFromInline internal func _atomicLoadThenBitwiseAnd( - with operand: _AtomicInt16Storage, + with operand: Int16, ordering: AtomicUpdateOrdering - ) -> _AtomicInt16Storage { + ) -> Int16 { switch ordering { case .relaxed: return _sa_fetch_and_relaxed_Int16( @@ -885,9 +885,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt16Storage { @usableFromInline internal func _atomicLoadThenBitwiseOr( - with operand: _AtomicInt16Storage, + with operand: Int16, ordering: AtomicUpdateOrdering - ) -> _AtomicInt16Storage { + ) -> Int16 { switch ordering { case .relaxed: return _sa_fetch_or_relaxed_Int16( @@ -918,9 +918,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt16Storage { @usableFromInline internal func _atomicLoadThenBitwiseXor( - with operand: _AtomicInt16Storage, + with operand: Int16, ordering: AtomicUpdateOrdering - ) -> _AtomicInt16Storage { + ) -> Int16 { switch ordering { case .relaxed: return _sa_fetch_xor_relaxed_Int16( @@ -949,7 +949,7 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt32Storage { @_alwaysEmitIntoClient @_transparent // Debug performance @usableFromInline - internal func _atomicLoad(ordering: AtomicLoadOrdering) -> _AtomicInt32Storage { + internal func _atomicLoad(ordering: AtomicLoadOrdering) -> Int32 { switch ordering { case .relaxed: return _sa_load_relaxed_Int32(self) @@ -969,7 +969,7 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt32Storage { @_transparent // Debug performance @usableFromInline internal func _atomicStore( - _ desired: _AtomicInt32Storage, + _ desired: Int32, ordering: AtomicStoreOrdering ) { switch ordering { @@ -990,9 +990,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt32Storage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicExchange( - _ desired: _AtomicInt32Storage, + _ desired: Int32, ordering: AtomicUpdateOrdering - ) -> _AtomicInt32Storage { + ) -> Int32 { switch ordering { case .relaxed: return _sa_exchange_relaxed_Int32(self, desired) @@ -1026,10 +1026,10 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt32Storage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicCompareExchange( - expected: _AtomicInt32Storage, - desired: _AtomicInt32Storage, + expected: Int32, + desired: Int32, ordering: AtomicUpdateOrdering - ) -> (exchanged: Bool, original: _AtomicInt32Storage) { + ) -> (exchanged: Bool, original: Int32) { var expected = expected let exchanged: Bool switch ordering { @@ -1075,11 +1075,11 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt32Storage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicCompareExchange( - expected: _AtomicInt32Storage, - desired: _AtomicInt32Storage, + expected: Int32, + desired: Int32, successOrdering: AtomicUpdateOrdering, failureOrdering: AtomicLoadOrdering - ) -> (exchanged: Bool, original: _AtomicInt32Storage) { + ) -> (exchanged: Bool, original: Int32) { // FIXME: LLVM doesn't support arbitrary ordering combinations // yet, so upgrade the success ordering when necessary so that it // is at least as "strong" as the failure case. @@ -1158,11 +1158,11 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt32Storage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicWeakCompareExchange( - expected: _AtomicInt32Storage, - desired: _AtomicInt32Storage, + expected: Int32, + desired: Int32, successOrdering: AtomicUpdateOrdering, failureOrdering: AtomicLoadOrdering - ) -> (exchanged: Bool, original: _AtomicInt32Storage) { + ) -> (exchanged: Bool, original: Int32) { // FIXME: LLVM doesn't support arbitrary ordering combinations // yet, so upgrade the success ordering when necessary so that it // is at least as "strong" as the failure case. @@ -1233,9 +1233,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt32Storage { @usableFromInline internal func _atomicLoadThenWrappingIncrement( - by operand: _AtomicInt32Storage, + by operand: Int32, ordering: AtomicUpdateOrdering - ) -> _AtomicInt32Storage { + ) -> Int32 { switch ordering { case .relaxed: return _sa_fetch_add_relaxed_Int32( @@ -1269,9 +1269,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt32Storage { @usableFromInline internal func _atomicLoadThenWrappingDecrement( - by operand: _AtomicInt32Storage, + by operand: Int32, ordering: AtomicUpdateOrdering - ) -> _AtomicInt32Storage { + ) -> Int32 { switch ordering { case .relaxed: return _sa_fetch_sub_relaxed_Int32( @@ -1302,9 +1302,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt32Storage { @usableFromInline internal func _atomicLoadThenBitwiseAnd( - with operand: _AtomicInt32Storage, + with operand: Int32, ordering: AtomicUpdateOrdering - ) -> _AtomicInt32Storage { + ) -> Int32 { switch ordering { case .relaxed: return _sa_fetch_and_relaxed_Int32( @@ -1335,9 +1335,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt32Storage { @usableFromInline internal func _atomicLoadThenBitwiseOr( - with operand: _AtomicInt32Storage, + with operand: Int32, ordering: AtomicUpdateOrdering - ) -> _AtomicInt32Storage { + ) -> Int32 { switch ordering { case .relaxed: return _sa_fetch_or_relaxed_Int32( @@ -1368,9 +1368,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt32Storage { @usableFromInline internal func _atomicLoadThenBitwiseXor( - with operand: _AtomicInt32Storage, + with operand: Int32, ordering: AtomicUpdateOrdering - ) -> _AtomicInt32Storage { + ) -> Int32 { switch ordering { case .relaxed: return _sa_fetch_xor_relaxed_Int32( @@ -1399,7 +1399,7 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt64Storage { @_alwaysEmitIntoClient @_transparent // Debug performance @usableFromInline - internal func _atomicLoad(ordering: AtomicLoadOrdering) -> _AtomicInt64Storage { + internal func _atomicLoad(ordering: AtomicLoadOrdering) -> Int64 { switch ordering { case .relaxed: return _sa_load_relaxed_Int64(self) @@ -1419,7 +1419,7 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt64Storage { @_transparent // Debug performance @usableFromInline internal func _atomicStore( - _ desired: _AtomicInt64Storage, + _ desired: Int64, ordering: AtomicStoreOrdering ) { switch ordering { @@ -1440,9 +1440,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt64Storage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicExchange( - _ desired: _AtomicInt64Storage, + _ desired: Int64, ordering: AtomicUpdateOrdering - ) -> _AtomicInt64Storage { + ) -> Int64 { switch ordering { case .relaxed: return _sa_exchange_relaxed_Int64(self, desired) @@ -1476,10 +1476,10 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt64Storage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicCompareExchange( - expected: _AtomicInt64Storage, - desired: _AtomicInt64Storage, + expected: Int64, + desired: Int64, ordering: AtomicUpdateOrdering - ) -> (exchanged: Bool, original: _AtomicInt64Storage) { + ) -> (exchanged: Bool, original: Int64) { var expected = expected let exchanged: Bool switch ordering { @@ -1525,11 +1525,11 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt64Storage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicCompareExchange( - expected: _AtomicInt64Storage, - desired: _AtomicInt64Storage, + expected: Int64, + desired: Int64, successOrdering: AtomicUpdateOrdering, failureOrdering: AtomicLoadOrdering - ) -> (exchanged: Bool, original: _AtomicInt64Storage) { + ) -> (exchanged: Bool, original: Int64) { // FIXME: LLVM doesn't support arbitrary ordering combinations // yet, so upgrade the success ordering when necessary so that it // is at least as "strong" as the failure case. @@ -1608,11 +1608,11 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt64Storage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicWeakCompareExchange( - expected: _AtomicInt64Storage, - desired: _AtomicInt64Storage, + expected: Int64, + desired: Int64, successOrdering: AtomicUpdateOrdering, failureOrdering: AtomicLoadOrdering - ) -> (exchanged: Bool, original: _AtomicInt64Storage) { + ) -> (exchanged: Bool, original: Int64) { // FIXME: LLVM doesn't support arbitrary ordering combinations // yet, so upgrade the success ordering when necessary so that it // is at least as "strong" as the failure case. @@ -1683,9 +1683,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt64Storage { @usableFromInline internal func _atomicLoadThenWrappingIncrement( - by operand: _AtomicInt64Storage, + by operand: Int64, ordering: AtomicUpdateOrdering - ) -> _AtomicInt64Storage { + ) -> Int64 { switch ordering { case .relaxed: return _sa_fetch_add_relaxed_Int64( @@ -1719,9 +1719,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt64Storage { @usableFromInline internal func _atomicLoadThenWrappingDecrement( - by operand: _AtomicInt64Storage, + by operand: Int64, ordering: AtomicUpdateOrdering - ) -> _AtomicInt64Storage { + ) -> Int64 { switch ordering { case .relaxed: return _sa_fetch_sub_relaxed_Int64( @@ -1752,9 +1752,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt64Storage { @usableFromInline internal func _atomicLoadThenBitwiseAnd( - with operand: _AtomicInt64Storage, + with operand: Int64, ordering: AtomicUpdateOrdering - ) -> _AtomicInt64Storage { + ) -> Int64 { switch ordering { case .relaxed: return _sa_fetch_and_relaxed_Int64( @@ -1785,9 +1785,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt64Storage { @usableFromInline internal func _atomicLoadThenBitwiseOr( - with operand: _AtomicInt64Storage, + with operand: Int64, ordering: AtomicUpdateOrdering - ) -> _AtomicInt64Storage { + ) -> Int64 { switch ordering { case .relaxed: return _sa_fetch_or_relaxed_Int64( @@ -1818,9 +1818,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicInt64Storage { @usableFromInline internal func _atomicLoadThenBitwiseXor( - with operand: _AtomicInt64Storage, + with operand: Int64, ordering: AtomicUpdateOrdering - ) -> _AtomicInt64Storage { + ) -> Int64 { switch ordering { case .relaxed: return _sa_fetch_xor_relaxed_Int64( @@ -1849,7 +1849,7 @@ extension UnsafeMutablePointer where Pointee == _AtomicIntStorage { @_alwaysEmitIntoClient @_transparent // Debug performance @usableFromInline - internal func _atomicLoad(ordering: AtomicLoadOrdering) -> _AtomicIntStorage { + internal func _atomicLoad(ordering: AtomicLoadOrdering) -> Int { switch ordering { case .relaxed: return _sa_load_relaxed_Int(self) @@ -1869,7 +1869,7 @@ extension UnsafeMutablePointer where Pointee == _AtomicIntStorage { @_transparent // Debug performance @usableFromInline internal func _atomicStore( - _ desired: _AtomicIntStorage, + _ desired: Int, ordering: AtomicStoreOrdering ) { switch ordering { @@ -1890,9 +1890,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicIntStorage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicExchange( - _ desired: _AtomicIntStorage, + _ desired: Int, ordering: AtomicUpdateOrdering - ) -> _AtomicIntStorage { + ) -> Int { switch ordering { case .relaxed: return _sa_exchange_relaxed_Int(self, desired) @@ -1926,10 +1926,10 @@ extension UnsafeMutablePointer where Pointee == _AtomicIntStorage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicCompareExchange( - expected: _AtomicIntStorage, - desired: _AtomicIntStorage, + expected: Int, + desired: Int, ordering: AtomicUpdateOrdering - ) -> (exchanged: Bool, original: _AtomicIntStorage) { + ) -> (exchanged: Bool, original: Int) { var expected = expected let exchanged: Bool switch ordering { @@ -1975,11 +1975,11 @@ extension UnsafeMutablePointer where Pointee == _AtomicIntStorage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicCompareExchange( - expected: _AtomicIntStorage, - desired: _AtomicIntStorage, + expected: Int, + desired: Int, successOrdering: AtomicUpdateOrdering, failureOrdering: AtomicLoadOrdering - ) -> (exchanged: Bool, original: _AtomicIntStorage) { + ) -> (exchanged: Bool, original: Int) { // FIXME: LLVM doesn't support arbitrary ordering combinations // yet, so upgrade the success ordering when necessary so that it // is at least as "strong" as the failure case. @@ -2058,11 +2058,11 @@ extension UnsafeMutablePointer where Pointee == _AtomicIntStorage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicWeakCompareExchange( - expected: _AtomicIntStorage, - desired: _AtomicIntStorage, + expected: Int, + desired: Int, successOrdering: AtomicUpdateOrdering, failureOrdering: AtomicLoadOrdering - ) -> (exchanged: Bool, original: _AtomicIntStorage) { + ) -> (exchanged: Bool, original: Int) { // FIXME: LLVM doesn't support arbitrary ordering combinations // yet, so upgrade the success ordering when necessary so that it // is at least as "strong" as the failure case. @@ -2133,9 +2133,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicIntStorage { @usableFromInline internal func _atomicLoadThenWrappingIncrement( - by operand: _AtomicIntStorage, + by operand: Int, ordering: AtomicUpdateOrdering - ) -> _AtomicIntStorage { + ) -> Int { switch ordering { case .relaxed: return _sa_fetch_add_relaxed_Int( @@ -2169,9 +2169,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicIntStorage { @usableFromInline internal func _atomicLoadThenWrappingDecrement( - by operand: _AtomicIntStorage, + by operand: Int, ordering: AtomicUpdateOrdering - ) -> _AtomicIntStorage { + ) -> Int { switch ordering { case .relaxed: return _sa_fetch_sub_relaxed_Int( @@ -2202,9 +2202,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicIntStorage { @usableFromInline internal func _atomicLoadThenBitwiseAnd( - with operand: _AtomicIntStorage, + with operand: Int, ordering: AtomicUpdateOrdering - ) -> _AtomicIntStorage { + ) -> Int { switch ordering { case .relaxed: return _sa_fetch_and_relaxed_Int( @@ -2235,9 +2235,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicIntStorage { @usableFromInline internal func _atomicLoadThenBitwiseOr( - with operand: _AtomicIntStorage, + with operand: Int, ordering: AtomicUpdateOrdering - ) -> _AtomicIntStorage { + ) -> Int { switch ordering { case .relaxed: return _sa_fetch_or_relaxed_Int( @@ -2268,9 +2268,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicIntStorage { @usableFromInline internal func _atomicLoadThenBitwiseXor( - with operand: _AtomicIntStorage, + with operand: Int, ordering: AtomicUpdateOrdering - ) -> _AtomicIntStorage { + ) -> Int { switch ordering { case .relaxed: return _sa_fetch_xor_relaxed_Int( @@ -2299,7 +2299,7 @@ extension UnsafeMutablePointer where Pointee == _AtomicDoubleWordStorage { @_alwaysEmitIntoClient @_transparent // Debug performance @usableFromInline - internal func _atomicLoad(ordering: AtomicLoadOrdering) -> _AtomicDoubleWordStorage { + internal func _atomicLoad(ordering: AtomicLoadOrdering) -> DoubleWord { switch ordering { case .relaxed: return _sa_load_relaxed_DoubleWord(self) @@ -2319,7 +2319,7 @@ extension UnsafeMutablePointer where Pointee == _AtomicDoubleWordStorage { @_transparent // Debug performance @usableFromInline internal func _atomicStore( - _ desired: _AtomicDoubleWordStorage, + _ desired: DoubleWord, ordering: AtomicStoreOrdering ) { switch ordering { @@ -2340,9 +2340,9 @@ extension UnsafeMutablePointer where Pointee == _AtomicDoubleWordStorage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicExchange( - _ desired: _AtomicDoubleWordStorage, + _ desired: DoubleWord, ordering: AtomicUpdateOrdering - ) -> _AtomicDoubleWordStorage { + ) -> DoubleWord { switch ordering { case .relaxed: return _sa_exchange_relaxed_DoubleWord(self, desired) @@ -2376,10 +2376,10 @@ extension UnsafeMutablePointer where Pointee == _AtomicDoubleWordStorage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicCompareExchange( - expected: _AtomicDoubleWordStorage, - desired: _AtomicDoubleWordStorage, + expected: DoubleWord, + desired: DoubleWord, ordering: AtomicUpdateOrdering - ) -> (exchanged: Bool, original: _AtomicDoubleWordStorage) { + ) -> (exchanged: Bool, original: DoubleWord) { var expected = expected let exchanged: Bool switch ordering { @@ -2425,11 +2425,11 @@ extension UnsafeMutablePointer where Pointee == _AtomicDoubleWordStorage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicCompareExchange( - expected: _AtomicDoubleWordStorage, - desired: _AtomicDoubleWordStorage, + expected: DoubleWord, + desired: DoubleWord, successOrdering: AtomicUpdateOrdering, failureOrdering: AtomicLoadOrdering - ) -> (exchanged: Bool, original: _AtomicDoubleWordStorage) { + ) -> (exchanged: Bool, original: DoubleWord) { // FIXME: LLVM doesn't support arbitrary ordering combinations // yet, so upgrade the success ordering when necessary so that it // is at least as "strong" as the failure case. @@ -2508,11 +2508,11 @@ extension UnsafeMutablePointer where Pointee == _AtomicDoubleWordStorage { @_alwaysEmitIntoClient @_transparent // Debug performance public func _atomicWeakCompareExchange( - expected: _AtomicDoubleWordStorage, - desired: _AtomicDoubleWordStorage, + expected: DoubleWord, + desired: DoubleWord, successOrdering: AtomicUpdateOrdering, failureOrdering: AtomicLoadOrdering - ) -> (exchanged: Bool, original: _AtomicDoubleWordStorage) { + ) -> (exchanged: Bool, original: DoubleWord) { // FIXME: LLVM doesn't support arbitrary ordering combinations // yet, so upgrade the success ordering when necessary so that it // is at least as "strong" as the failure case. diff --git a/Sources/Atomics/Types/DoubleWord.swift b/Sources/Atomics/Types/DoubleWord.swift index 9a260c7..5f51af7 100644 --- a/Sources/Atomics/Types/DoubleWord.swift +++ b/Sources/Atomics/Types/DoubleWord.swift @@ -10,7 +10,14 @@ // //===----------------------------------------------------------------------===// -#if ATOMICS_NATIVE_BUILTINS +// FIXME: The conditionals below have been carefully constructed to +// avoid confusing Swift 5.7; they can be sanitized once we drop support +// for that version. +#if compiler(>=5.9) +#if !ATOMICS_NATIVE_BUILTINS +#error("swift-atomics requires native builtins on Swift 5.9") +#endif + import Builtin #if _pointerBitWidth(_32) @@ -63,10 +70,14 @@ extension DoubleWord { } } -#else // !ATOMICS_NATIVE_BUILTINS +#else // compiler(>=5.9) + +#if ATOMICS_NATIVE_BUILTINS +#error("swift-atomics requires C shims on Swift versions below 5.9") +#endif import _AtomicsShims public typealias DoubleWord = _AtomicsShims.DoubleWord -#endif +#endif // compiler(>=5.9) extension DoubleWord { /// Initialize a new `DoubleWord` value given its high- and diff --git a/Sources/Atomics/Unmanaged extensions.swift b/Sources/Atomics/Unmanaged extensions.swift index 3b20f51..f2e07b3 100644 --- a/Sources/Atomics/Unmanaged extensions.swift +++ b/Sources/Atomics/Unmanaged extensions.swift @@ -16,6 +16,8 @@ internal func _sa_retain_n(_ object: UnsafeMutableRawPointer, _ delta: UInt32) @_silgen_name("_sa_release_n") internal func _sa_release_n(_ object: UnsafeMutableRawPointer, _ delta: UInt32) +#elseif ATOMICS_NATIVE_BUILTINS +@_implementationOnly import _AtomicsShims #else import _AtomicsShims #endif diff --git a/Sources/_AtomicsShims/CMakeLists.txt b/Sources/_AtomicsShims/CMakeLists.txt index 391519e..eb28ed9 100644 --- a/Sources/_AtomicsShims/CMakeLists.txt +++ b/Sources/_AtomicsShims/CMakeLists.txt @@ -11,6 +11,9 @@ add_library(_AtomicsShims STATIC src/_AtomicsShims.c) target_include_directories(_AtomicsShims PUBLIC include) +target_compile_options(_AtomicsShims PUBLIC + "$<$:SHELL:${ATOMICS_SWIFT_FLAGS}>" + "$<$:SHELL:${ATOMICS_C_FLAGS}>") if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") target_compile_options(_AtomicsShims PUBLIC "$<$:SHELL:-Xcc -mcx16>") diff --git a/Sources/_AtomicsShims/include/_AtomicsShims.h b/Sources/_AtomicsShims/include/_AtomicsShims.h index 292e12a..d9a859e 100644 --- a/Sources/_AtomicsShims/include/_AtomicsShims.h +++ b/Sources/_AtomicsShims/include/_AtomicsShims.h @@ -98,11 +98,10 @@ SWIFTATOMIC_THREAD_FENCE_FN(seq_cst) // Atomic load #define SWIFTATOMIC_LOAD_FN(swiftType, cType, order) \ SWIFTATOMIC_INLINE \ - _sa_##swiftType _sa_load_##order##_##swiftType(_sa_##swiftType *ptr) \ + cType _sa_load_##order##_##swiftType(_sa_##swiftType *ptr) \ { \ - cType value = atomic_load_explicit( \ + return atomic_load_explicit( \ &ptr->value, memory_order_##order); \ - return (_sa_##swiftType) { .value = value }; \ } // Atomic store @@ -110,22 +109,21 @@ SWIFTATOMIC_THREAD_FENCE_FN(seq_cst) SWIFTATOMIC_INLINE \ void _sa_store_##order##_##swiftType( \ _sa_##swiftType *ptr, \ - _sa_##swiftType desired) \ + cType desired) \ { \ atomic_store_explicit( \ - &ptr->value, desired.value, memory_order_##order); \ + &ptr->value, desired, memory_order_##order); \ } // Atomic exchange #define SWIFTATOMIC_EXCHANGE_FN(swiftType, cType, order) \ SWIFTATOMIC_INLINE \ - _sa_##swiftType _sa_exchange_##order##_##swiftType( \ + cType _sa_exchange_##order##_##swiftType( \ _sa_##swiftType *ptr, \ - _sa_##swiftType desired) \ + cType desired) \ { \ - cType value = atomic_exchange_explicit( \ - &ptr->value, desired.value, memory_order_##order); \ - return (_sa_##swiftType) { .value = value }; \ + return atomic_exchange_explicit( \ + &ptr->value, desired, memory_order_##order); \ } // Atomic compare/exchange @@ -134,13 +132,13 @@ SWIFTATOMIC_THREAD_FENCE_FN(seq_cst) bool \ _sa_cmpxchg_##_kind##_##succ##_##fail##_##swiftType( \ _sa_##swiftType *ptr, \ - _sa_##swiftType *expected, \ - _sa_##swiftType desired) \ + cType *expected, \ + cType desired) \ { \ return atomic_compare_exchange_##_kind##_explicit( \ &ptr->value, \ - &expected->value, \ - desired.value, \ + expected, \ + desired, \ memory_order_##succ, \ memory_order_##fail); \ } @@ -148,13 +146,12 @@ SWIFTATOMIC_THREAD_FENCE_FN(seq_cst) // Atomic integer operations #define SWIFTATOMIC_INTEGER_FN(op, swiftType, cType, order) \ SWIFTATOMIC_INLINE \ - _sa_##swiftType _sa_fetch_##op##_##order##_##swiftType( \ + cType _sa_fetch_##op##_##order##_##swiftType( \ _sa_##swiftType *ptr, \ - _sa_##swiftType operand) \ + cType operand) \ { \ - cType value = atomic_fetch_##op##_explicit( \ - &ptr->value, operand.value, memory_order_##order); \ - return (_sa_##swiftType) { .value = value }; \ + return atomic_fetch_##op##_explicit( \ + &ptr->value, operand, memory_order_##order); \ } // Functions for each supported operation + memory ordering combination diff --git a/Tests/AtomicsTests/Basics/BasicTests.gyb-template b/Tests/AtomicsTests/Basics/BasicTests.gyb-template index 32251f1..5bdb294 100644 --- a/Tests/AtomicsTests/Basics/BasicTests.gyb-template +++ b/Tests/AtomicsTests/Basics/BasicTests.gyb-template @@ -125,13 +125,12 @@ class BasicAtomic${label}Tests: XCTestCase { % end -% for operation in ["compareExchange", "weakCompareExchange"]: -% for (order, _, _, _, _) in updateOrderings: - func test_${operation}_${order}() { +% for (order, _, _, _, _) in updateOrderings: + func test_compareExchange_${order}() { let v: UnsafeAtomic<${type}> = .create(${a}) defer { v.destroy() } - var (exchanged, original): (Bool, ${type}) = v.${operation}( + var (exchanged, original): (Bool, ${type}) = v.compareExchange( expected: ${a}, desired: ${b}, ordering: .${order}) @@ -139,7 +138,7 @@ class BasicAtomic${label}Tests: XCTestCase { XCTAssertEqual(original, ${a}) XCTAssertEqual(v.load(ordering: .relaxed), ${b}) - (exchanged, original) = v.${operation}( + (exchanged, original) = v.compareExchange( expected: ${a}, desired: ${b}, ordering: .${order}) @@ -147,7 +146,7 @@ class BasicAtomic${label}Tests: XCTestCase { XCTAssertEqual(original, ${b}) XCTAssertEqual(v.load(ordering: .relaxed), ${b}) - (exchanged, original) = v.${operation}( + (exchanged, original) = v.compareExchange( expected: ${b}, desired: ${a}, ordering: .${order}) @@ -155,7 +154,7 @@ class BasicAtomic${label}Tests: XCTestCase { XCTAssertEqual(original, ${b}) XCTAssertEqual(v.load(ordering: .relaxed), ${a}) - (exchanged, original) = v.${operation}( + (exchanged, original) = v.compareExchange( expected: ${b}, desired: ${a}, ordering: .${order}) @@ -164,17 +163,59 @@ class BasicAtomic${label}Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), ${a}) } -% end % end -% for operation in ["compareExchange", "weakCompareExchange"]: -% for (successorder, _, _, _, _) in updateOrderings: -% for (failorder, _, _, _) in loadOrderings: - func test_${operation}_${successorder}_${failorder}() { +% for (order, _, _, _, _) in updateOrderings: + func test_weakCompareExchange_${order}() { + let v: UnsafeAtomic<${type}> = .create(${a}) + defer { v.destroy() } + + var (exchanged, original): (Bool, ${type}) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: ${a}, + desired: ${b}, + ordering: .${order}) + } while !exchanged + XCTAssertEqual(original, ${a}) + XCTAssertEqual(v.load(ordering: .relaxed), ${b}) + + (exchanged, original) = v.weakCompareExchange( + expected: ${a}, + desired: ${b}, + ordering: .${order}) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, ${b}) + XCTAssertEqual(v.load(ordering: .relaxed), ${b}) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: ${b}, + desired: ${a}, + ordering: .${order}) + } while !exchanged + XCTAssertEqual(original, ${b}) + XCTAssertEqual(v.load(ordering: .relaxed), ${a}) + + (exchanged, original) = v.weakCompareExchange( + expected: ${b}, + desired: ${a}, + ordering: .${order}) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, ${a}) + XCTAssertEqual(v.load(ordering: .relaxed), ${a}) + } + +% end + +% for (successorder, _, _, _, _) in updateOrderings: +% for (failorder, _, _, _) in loadOrderings: + func test_compareExchange_${successorder}_${failorder}() { let v: UnsafeAtomic<${type}> = .create(${a}) defer { v.destroy() } - var (exchanged, original): (Bool, ${type}) = v.${operation}( + var (exchanged, original): (Bool, ${type}) = v.compareExchange( expected: ${a}, desired: ${b}, successOrdering: .${successorder}, @@ -183,7 +224,7 @@ class BasicAtomic${label}Tests: XCTestCase { XCTAssertEqual(original, ${a}) XCTAssertEqual(v.load(ordering: .relaxed), ${b}) - (exchanged, original) = v.${operation}( + (exchanged, original) = v.compareExchange( expected: ${a}, desired: ${b}, successOrdering: .${successorder}, @@ -192,7 +233,7 @@ class BasicAtomic${label}Tests: XCTestCase { XCTAssertEqual(original, ${b}) XCTAssertEqual(v.load(ordering: .relaxed), ${b}) - (exchanged, original) = v.${operation}( + (exchanged, original) = v.compareExchange( expected: ${b}, desired: ${a}, successOrdering: .${successorder}, @@ -201,7 +242,56 @@ class BasicAtomic${label}Tests: XCTestCase { XCTAssertEqual(original, ${b}) XCTAssertEqual(v.load(ordering: .relaxed), ${a}) - (exchanged, original) = v.${operation}( + (exchanged, original) = v.compareExchange( + expected: ${b}, + desired: ${a}, + successOrdering: .${successorder}, + failureOrdering: .${failorder}) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, ${a}) + XCTAssertEqual(v.load(ordering: .relaxed), ${a}) + } + +% end +% end + +% for (successorder, _, _, _, _) in updateOrderings: +% for (failorder, _, _, _) in loadOrderings: + func test_weakCompareExchange_${successorder}_${failorder}() { + let v: UnsafeAtomic<${type}> = .create(${a}) + defer { v.destroy() } + + var (exchanged, original): (Bool, ${type}) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: ${a}, + desired: ${b}, + successOrdering: .${successorder}, + failureOrdering: .${failorder}) + } while !exchanged + XCTAssertEqual(original, ${a}) + XCTAssertEqual(v.load(ordering: .relaxed), ${b}) + + (exchanged, original) = v.weakCompareExchange( + expected: ${a}, + desired: ${b}, + successOrdering: .${successorder}, + failureOrdering: .${failorder}) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, ${b}) + XCTAssertEqual(v.load(ordering: .relaxed), ${b}) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: ${b}, + desired: ${a}, + successOrdering: .${successorder}, + failureOrdering: .${failorder}) + } while !exchanged + XCTAssertEqual(original, ${b}) + XCTAssertEqual(v.load(ordering: .relaxed), ${a}) + + (exchanged, original) = v.weakCompareExchange( expected: ${b}, desired: ${a}, successOrdering: .${successorder}, @@ -211,7 +301,6 @@ class BasicAtomic${label}Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), ${a}) } -% end % end % end diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicBoolTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicBoolTests.swift index c4079d1..a553bb3 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicBoolTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicBoolTests.swift @@ -359,15 +359,19 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), true) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -379,11 +383,12 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -400,11 +405,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -416,11 +424,12 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -437,11 +446,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -453,11 +465,12 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -474,11 +487,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -490,11 +506,12 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -511,11 +528,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -527,11 +547,12 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -1160,16 +1181,19 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), true) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -1182,12 +1206,13 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -1205,12 +1230,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -1223,12 +1250,13 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -1246,12 +1274,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -1264,12 +1294,13 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -1287,12 +1318,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -1305,12 +1338,13 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -1328,12 +1362,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -1346,12 +1382,13 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -1369,12 +1406,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -1387,12 +1426,13 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -1410,12 +1450,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -1428,12 +1470,13 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -1451,12 +1494,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -1469,12 +1514,13 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -1492,12 +1538,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -1510,12 +1558,13 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -1533,12 +1582,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -1551,12 +1602,13 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -1574,12 +1626,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -1592,12 +1646,13 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -1615,12 +1670,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -1633,12 +1690,13 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -1656,12 +1714,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -1674,12 +1734,13 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -1697,12 +1758,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -1715,12 +1778,13 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) @@ -1738,12 +1802,14 @@ class BasicAtomicBoolTests: XCTestCase { let v: UnsafeAtomic = .create(true) defer { v.destroy() } - var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( - expected: true, - desired: false, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Bool) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, true) XCTAssertEqual(v.load(ordering: .relaxed), false) @@ -1756,12 +1822,13 @@ class BasicAtomicBoolTests: XCTestCase { XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), false) - (exchanged, original) = v.weakCompareExchange( - expected: false, - desired: true, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, false) XCTAssertEqual(v.load(ordering: .relaxed), true) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicDoubleWordTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicDoubleWordTests.swift index 8d9adfa..cce1947 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicDoubleWordTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicDoubleWordTests.swift @@ -359,15 +359,19 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -379,11 +383,12 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -400,11 +405,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -416,11 +424,12 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -437,11 +446,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -453,11 +465,12 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -474,11 +487,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -490,11 +506,12 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -511,11 +528,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -527,11 +547,12 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -1160,16 +1181,19 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -1182,12 +1206,13 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -1205,12 +1230,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -1223,12 +1250,13 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -1246,12 +1274,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -1264,12 +1294,13 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -1287,12 +1318,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -1305,12 +1338,13 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -1328,12 +1362,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -1346,12 +1382,13 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -1369,12 +1406,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -1387,12 +1426,13 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -1410,12 +1450,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -1428,12 +1470,13 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -1451,12 +1494,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -1469,12 +1514,13 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -1492,12 +1538,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -1510,12 +1558,13 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -1533,12 +1582,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -1551,12 +1602,13 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -1574,12 +1626,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -1592,12 +1646,13 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -1615,12 +1670,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -1633,12 +1690,13 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -1656,12 +1714,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -1674,12 +1734,13 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -1697,12 +1758,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -1715,12 +1778,13 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) @@ -1738,12 +1802,14 @@ class BasicAtomicDoubleWordTests: XCTestCase { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) defer { v.destroy() } - var (exchanged, original): (Bool, DoubleWord) = v.weakCompareExchange( - expected: DoubleWord(first: 100, second: 64), - desired: DoubleWord(first: 50, second: 32), - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, DoubleWord) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) @@ -1756,12 +1822,13 @@ class BasicAtomicDoubleWordTests: XCTestCase { XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) - (exchanged, original) = v.weakCompareExchange( - expected: DoubleWord(first: 50, second: 32), - desired: DoubleWord(first: 100, second: 64), - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt16Tests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt16Tests.swift index 48c48b2..1b0ebda 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt16Tests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt16Tests.swift @@ -359,15 +359,19 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -379,11 +383,12 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -400,11 +405,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -416,11 +424,12 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -437,11 +446,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -453,11 +465,12 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -474,11 +487,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -490,11 +506,12 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -511,11 +528,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -527,11 +547,12 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1160,16 +1181,19 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1182,12 +1206,13 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1205,12 +1230,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1223,12 +1250,13 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1246,12 +1274,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1264,12 +1294,13 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1287,12 +1318,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1305,12 +1338,13 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1328,12 +1362,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1346,12 +1382,13 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1369,12 +1406,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1387,12 +1426,13 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1410,12 +1450,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1428,12 +1470,13 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1451,12 +1494,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1469,12 +1514,13 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1492,12 +1538,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1510,12 +1558,13 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1533,12 +1582,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1551,12 +1602,13 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1574,12 +1626,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1592,12 +1646,13 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1615,12 +1670,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1633,12 +1690,13 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1656,12 +1714,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1674,12 +1734,13 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1697,12 +1758,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1715,12 +1778,13 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1738,12 +1802,14 @@ class BasicAtomicInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1756,12 +1822,13 @@ class BasicAtomicInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt32Tests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt32Tests.swift index b755452..cd444a2 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt32Tests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt32Tests.swift @@ -359,15 +359,19 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -379,11 +383,12 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -400,11 +405,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -416,11 +424,12 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -437,11 +446,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -453,11 +465,12 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -474,11 +487,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -490,11 +506,12 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -511,11 +528,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -527,11 +547,12 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1160,16 +1181,19 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1182,12 +1206,13 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1205,12 +1230,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1223,12 +1250,13 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1246,12 +1274,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1264,12 +1294,13 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1287,12 +1318,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1305,12 +1338,13 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1328,12 +1362,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1346,12 +1382,13 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1369,12 +1406,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1387,12 +1426,13 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1410,12 +1450,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1428,12 +1470,13 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1451,12 +1494,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1469,12 +1514,13 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1492,12 +1538,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1510,12 +1558,13 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1533,12 +1582,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1551,12 +1602,13 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1574,12 +1626,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1592,12 +1646,13 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1615,12 +1670,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1633,12 +1690,13 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1656,12 +1714,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1674,12 +1734,13 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1697,12 +1758,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1715,12 +1778,13 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1738,12 +1802,14 @@ class BasicAtomicInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1756,12 +1822,13 @@ class BasicAtomicInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt64Tests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt64Tests.swift index bda8b1c..dda74f6 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt64Tests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt64Tests.swift @@ -359,15 +359,19 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -379,11 +383,12 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -400,11 +405,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -416,11 +424,12 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -437,11 +446,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -453,11 +465,12 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -474,11 +487,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -490,11 +506,12 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -511,11 +528,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -527,11 +547,12 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1160,16 +1181,19 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1182,12 +1206,13 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1205,12 +1230,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1223,12 +1250,13 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1246,12 +1274,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1264,12 +1294,13 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1287,12 +1318,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1305,12 +1338,13 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1328,12 +1362,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1346,12 +1382,13 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1369,12 +1406,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1387,12 +1426,13 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1410,12 +1450,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1428,12 +1470,13 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1451,12 +1494,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1469,12 +1514,13 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1492,12 +1538,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1510,12 +1558,13 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1533,12 +1582,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1551,12 +1602,13 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1574,12 +1626,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1592,12 +1646,13 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1615,12 +1670,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1633,12 +1690,13 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1656,12 +1714,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1674,12 +1734,13 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1697,12 +1758,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1715,12 +1778,13 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1738,12 +1802,14 @@ class BasicAtomicInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1756,12 +1822,13 @@ class BasicAtomicInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt8Tests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt8Tests.swift index b5c33e2..8b49885 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt8Tests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt8Tests.swift @@ -359,15 +359,19 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -379,11 +383,12 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -400,11 +405,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -416,11 +424,12 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -437,11 +446,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -453,11 +465,12 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -474,11 +487,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -490,11 +506,12 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -511,11 +528,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -527,11 +547,12 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1160,16 +1181,19 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1182,12 +1206,13 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1205,12 +1230,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1223,12 +1250,13 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1246,12 +1274,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1264,12 +1294,13 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1287,12 +1318,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1305,12 +1338,13 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1328,12 +1362,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1346,12 +1382,13 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1369,12 +1406,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1387,12 +1426,13 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1410,12 +1450,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1428,12 +1470,13 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1451,12 +1494,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1469,12 +1514,13 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1492,12 +1538,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1510,12 +1558,13 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1533,12 +1582,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1551,12 +1602,13 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1574,12 +1626,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1592,12 +1646,13 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1615,12 +1670,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1633,12 +1690,13 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1656,12 +1714,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1674,12 +1734,13 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1697,12 +1758,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1715,12 +1778,13 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1738,12 +1802,14 @@ class BasicAtomicInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1756,12 +1822,13 @@ class BasicAtomicInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicIntTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicIntTests.swift index d24f881..39ab68e 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicIntTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicIntTests.swift @@ -359,15 +359,19 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -379,11 +383,12 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -400,11 +405,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -416,11 +424,12 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -437,11 +446,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -453,11 +465,12 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -474,11 +487,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -490,11 +506,12 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -511,11 +528,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -527,11 +547,12 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1160,16 +1181,19 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1182,12 +1206,13 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1205,12 +1230,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1223,12 +1250,13 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1246,12 +1274,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1264,12 +1294,13 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1287,12 +1318,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1305,12 +1338,13 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1328,12 +1362,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1346,12 +1382,13 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1369,12 +1406,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1387,12 +1426,13 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1410,12 +1450,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1428,12 +1470,13 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1451,12 +1494,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1469,12 +1514,13 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1492,12 +1538,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1510,12 +1558,13 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1533,12 +1582,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1551,12 +1602,13 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1574,12 +1626,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1592,12 +1646,13 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1615,12 +1670,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1633,12 +1690,13 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1656,12 +1714,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1674,12 +1734,13 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1697,12 +1758,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1715,12 +1778,13 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1738,12 +1802,14 @@ class BasicAtomicIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, Int) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Int) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1756,12 +1822,13 @@ class BasicAtomicIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicMutablePointerTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicMutablePointerTests.swift index 2240630..45dd4dd 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicMutablePointerTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicMutablePointerTests.swift @@ -380,15 +380,19 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -400,11 +404,12 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -421,11 +426,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -437,11 +445,12 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -458,11 +467,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -474,11 +486,12 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -495,11 +508,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -511,11 +527,12 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -532,11 +549,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -548,11 +568,12 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -1181,16 +1202,19 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1203,12 +1227,13 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -1226,12 +1251,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1244,12 +1271,13 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -1267,12 +1295,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1285,12 +1315,13 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -1308,12 +1339,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1326,12 +1359,13 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -1349,12 +1383,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1367,12 +1403,13 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -1390,12 +1427,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1408,12 +1447,13 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -1431,12 +1471,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1449,12 +1491,13 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -1472,12 +1515,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1490,12 +1535,13 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -1513,12 +1559,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1531,12 +1579,13 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -1554,12 +1603,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1572,12 +1623,13 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -1595,12 +1647,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1613,12 +1667,13 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -1636,12 +1691,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1654,12 +1711,13 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -1677,12 +1735,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1695,12 +1755,13 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -1718,12 +1779,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1736,12 +1799,13 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) @@ -1759,12 +1823,14 @@ class BasicAtomicMutablePointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_mfoo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( - expected: _mfoo1, - desired: _mfoo2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo1) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1777,12 +1843,13 @@ class BasicAtomicMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: _mfoo1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicMutableRawPointerTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicMutableRawPointerTests.swift index 0056e52..dbad2fc 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicMutableRawPointerTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicMutableRawPointerTests.swift @@ -369,15 +369,19 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -389,11 +393,12 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -410,11 +415,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -426,11 +434,12 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -447,11 +456,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -463,11 +475,12 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -484,11 +497,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -500,11 +516,12 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -521,11 +538,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -537,11 +557,12 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -1170,16 +1191,19 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1192,12 +1216,13 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -1215,12 +1240,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1233,12 +1260,13 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -1256,12 +1284,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1274,12 +1304,13 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -1297,12 +1328,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1315,12 +1348,13 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -1338,12 +1372,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1356,12 +1392,13 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -1379,12 +1416,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1397,12 +1436,13 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -1420,12 +1460,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1438,12 +1480,13 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -1461,12 +1504,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1479,12 +1524,13 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -1502,12 +1548,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1520,12 +1568,13 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -1543,12 +1592,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1561,12 +1612,13 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -1584,12 +1636,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1602,12 +1656,13 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -1625,12 +1680,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1643,12 +1700,13 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -1666,12 +1724,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1684,12 +1744,13 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -1707,12 +1768,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1725,12 +1788,13 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) @@ -1748,12 +1812,14 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_mraw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( - expected: _mraw1, - desired: _mraw2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw1) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1766,12 +1832,13 @@ class BasicAtomicMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: _mraw1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalMutablePointerTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalMutablePointerTests.swift index f61687d..9ccb6e8 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalMutablePointerTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalMutablePointerTests.swift @@ -380,15 +380,19 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), nil) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -400,11 +404,12 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -421,11 +426,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -437,11 +445,12 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -458,11 +467,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -474,11 +486,12 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -495,11 +508,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -511,11 +527,12 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -532,11 +549,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -548,11 +568,12 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1181,16 +1202,19 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), nil) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1203,12 +1227,13 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1226,12 +1251,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1244,12 +1271,13 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1267,12 +1295,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1285,12 +1315,13 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1308,12 +1339,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1326,12 +1359,13 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1349,12 +1383,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1367,12 +1403,13 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1390,12 +1427,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1408,12 +1447,13 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1431,12 +1471,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1449,12 +1491,13 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1472,12 +1515,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1490,12 +1535,13 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1513,12 +1559,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1531,12 +1579,13 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1554,12 +1603,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1572,12 +1623,13 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1595,12 +1647,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1613,12 +1667,13 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1636,12 +1691,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1654,12 +1711,13 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1677,12 +1735,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1695,12 +1755,13 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1718,12 +1779,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1736,12 +1799,13 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1759,12 +1823,14 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( - expected: nil, - desired: _mfoo2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutablePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) @@ -1777,12 +1843,13 @@ class BasicAtomicOptionalMutablePointerTests: XCTestCase { XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) - (exchanged, original) = v.weakCompareExchange( - expected: _mfoo2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mfoo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalMutableRawPointerTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalMutableRawPointerTests.swift index 9eb8929..29dc3f2 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalMutableRawPointerTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalMutableRawPointerTests.swift @@ -369,15 +369,19 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), nil) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -389,11 +393,12 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -410,11 +415,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -426,11 +434,12 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -447,11 +456,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -463,11 +475,12 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -484,11 +497,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -500,11 +516,12 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -521,11 +538,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -537,11 +557,12 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1170,16 +1191,19 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), nil) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1192,12 +1216,13 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1215,12 +1240,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1233,12 +1260,13 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1256,12 +1284,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1274,12 +1304,13 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1297,12 +1328,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1315,12 +1348,13 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1338,12 +1372,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1356,12 +1392,13 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1379,12 +1416,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1397,12 +1436,13 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1420,12 +1460,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1438,12 +1480,13 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1461,12 +1504,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1479,12 +1524,13 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1502,12 +1548,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1520,12 +1568,13 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1543,12 +1592,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1561,12 +1612,13 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1584,12 +1636,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1602,12 +1656,13 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1625,12 +1680,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1643,12 +1700,13 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1666,12 +1724,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1684,12 +1744,13 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1707,12 +1768,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1725,12 +1788,13 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1748,12 +1812,14 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _mraw2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) @@ -1766,12 +1832,13 @@ class BasicAtomicOptionalMutableRawPointerTests: XCTestCase { XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) - (exchanged, original) = v.weakCompareExchange( - expected: _mraw2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _mraw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalPointerTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalPointerTests.swift index 7e5a58e..5c40656 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalPointerTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalPointerTests.swift @@ -380,15 +380,19 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), nil) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -400,11 +404,12 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -421,11 +426,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -437,11 +445,12 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -458,11 +467,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -474,11 +486,12 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -495,11 +508,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -511,11 +527,12 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -532,11 +549,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -548,11 +568,12 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1181,16 +1202,19 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), nil) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1203,12 +1227,13 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1226,12 +1251,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1244,12 +1271,13 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1267,12 +1295,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1285,12 +1315,13 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1308,12 +1339,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1326,12 +1359,13 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1349,12 +1383,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1367,12 +1403,13 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1390,12 +1427,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1408,12 +1447,13 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1431,12 +1471,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1449,12 +1491,13 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1472,12 +1515,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1490,12 +1535,13 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1513,12 +1559,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1531,12 +1579,13 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1554,12 +1603,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1572,12 +1623,13 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1595,12 +1647,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1613,12 +1667,13 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1636,12 +1691,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1654,12 +1711,13 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1677,12 +1735,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1695,12 +1755,13 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1718,12 +1779,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1736,12 +1799,13 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1759,12 +1823,14 @@ class BasicAtomicOptionalPointerTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( - expected: nil, - desired: _foo2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1777,12 +1843,13 @@ class BasicAtomicOptionalPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), nil) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalRawPointerTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalRawPointerTests.swift index 4a36fe0..f3c47ef 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalRawPointerTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalRawPointerTests.swift @@ -369,15 +369,19 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), nil) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -389,11 +393,12 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -410,11 +415,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -426,11 +434,12 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -447,11 +456,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -463,11 +475,12 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -484,11 +497,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -500,11 +516,12 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -521,11 +538,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -537,11 +557,12 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1170,16 +1191,19 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), nil) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1192,12 +1216,13 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1215,12 +1240,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1233,12 +1260,13 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1256,12 +1284,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1274,12 +1304,13 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1297,12 +1328,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1315,12 +1348,13 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1338,12 +1372,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1356,12 +1392,13 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1379,12 +1416,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1397,12 +1436,13 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1420,12 +1460,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1438,12 +1480,13 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1461,12 +1504,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1479,12 +1524,13 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1502,12 +1548,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1520,12 +1568,13 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1543,12 +1592,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1561,12 +1612,13 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1584,12 +1636,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1602,12 +1656,13 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1625,12 +1680,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1643,12 +1700,13 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1666,12 +1724,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1684,12 +1744,13 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1707,12 +1768,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1725,12 +1788,13 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1748,12 +1812,14 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( - expected: nil, - desired: _raw2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1766,12 +1832,13 @@ class BasicAtomicOptionalRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), nil) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalRawRepresentableTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalRawRepresentableTests.swift index 4ba56a6..9ad2995 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalRawRepresentableTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalRawRepresentableTests.swift @@ -359,15 +359,19 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -379,11 +383,12 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -400,11 +405,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -416,11 +424,12 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -437,11 +446,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -453,11 +465,12 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -474,11 +487,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -490,11 +506,12 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -511,11 +528,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -527,11 +547,12 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -1160,16 +1181,19 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1182,12 +1206,13 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -1205,12 +1230,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1223,12 +1250,13 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -1246,12 +1274,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1264,12 +1294,13 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -1287,12 +1318,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1305,12 +1338,13 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -1328,12 +1362,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1346,12 +1382,13 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -1369,12 +1406,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1387,12 +1426,13 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -1410,12 +1450,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1428,12 +1470,13 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -1451,12 +1494,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1469,12 +1514,13 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -1492,12 +1538,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1510,12 +1558,13 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -1533,12 +1582,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1551,12 +1602,13 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -1574,12 +1626,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1592,12 +1646,13 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -1615,12 +1670,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1633,12 +1690,13 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -1656,12 +1714,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1674,12 +1734,13 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -1697,12 +1758,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1715,12 +1778,13 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) @@ -1738,12 +1802,14 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Hyacinth.bucket) defer { v.destroy() } - var (exchanged, original): (Bool, Hyacinth?) = v.weakCompareExchange( - expected: Hyacinth.bucket, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Hyacinth?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Hyacinth.bucket) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1756,12 +1822,13 @@ class BasicAtomicOptionalRawRepresentableTests: XCTestCase { XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), nil) - (exchanged, original) = v.weakCompareExchange( - expected: nil, - desired: Hyacinth.bucket, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalReferenceTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalReferenceTests.swift index 0df9852..ac83607 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalReferenceTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalReferenceTests.swift @@ -361,15 +361,19 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), nil) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -381,11 +385,12 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -402,11 +407,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -418,11 +426,12 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -439,11 +448,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -455,11 +467,12 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -476,11 +489,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -492,11 +508,12 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -513,11 +530,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -529,11 +549,12 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1162,16 +1183,19 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), nil) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1184,12 +1208,13 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1207,12 +1232,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1225,12 +1252,13 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1248,12 +1276,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1266,12 +1296,13 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1289,12 +1320,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1307,12 +1340,13 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1330,12 +1364,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1348,12 +1384,13 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1371,12 +1408,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1389,12 +1428,13 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1412,12 +1452,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1430,12 +1472,13 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1453,12 +1496,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1471,12 +1516,13 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1494,12 +1540,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1512,12 +1560,13 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1535,12 +1584,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1553,12 +1604,13 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1576,12 +1628,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1594,12 +1648,13 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1617,12 +1672,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1635,12 +1692,13 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1658,12 +1716,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1676,12 +1736,13 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1699,12 +1760,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1717,12 +1780,13 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1740,12 +1804,14 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( - expected: nil, - desired: _baz2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1758,12 +1824,13 @@ class BasicAtomicOptionalReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), nil) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalUnmanagedTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalUnmanagedTests.swift index 17bb682..2e697e8 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalUnmanagedTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalUnmanagedTests.swift @@ -366,15 +366,19 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), nil) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -386,11 +390,12 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -407,11 +412,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -423,11 +431,12 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -444,11 +453,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -460,11 +472,12 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -481,11 +494,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -497,11 +513,12 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -518,11 +535,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -534,11 +554,12 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1167,16 +1188,19 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), nil) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1189,12 +1213,13 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1212,12 +1237,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1230,12 +1257,13 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1253,12 +1281,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1271,12 +1301,13 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1294,12 +1325,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1312,12 +1345,13 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1335,12 +1369,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1353,12 +1389,13 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1376,12 +1413,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1394,12 +1433,13 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1417,12 +1457,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1435,12 +1477,13 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1458,12 +1501,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1476,12 +1521,13 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1499,12 +1545,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1517,12 +1565,13 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1540,12 +1589,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1558,12 +1609,13 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1581,12 +1633,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1599,12 +1653,13 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1622,12 +1677,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1640,12 +1697,13 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1663,12 +1721,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1681,12 +1741,13 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1704,12 +1765,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1722,12 +1785,13 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) @@ -1745,12 +1809,14 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { let v: UnsafeAtomic?> = .create(nil) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( - expected: nil, - desired: _bar2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged?) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, nil) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1763,12 +1829,13 @@ class BasicAtomicOptionalUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: nil, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), nil) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicPointerTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicPointerTests.swift index b1cb328..8fcc1f2 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicPointerTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicPointerTests.swift @@ -380,15 +380,19 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), _foo1) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -400,11 +404,12 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -421,11 +426,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -437,11 +445,12 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -458,11 +467,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -474,11 +486,12 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -495,11 +508,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -511,11 +527,12 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -532,11 +549,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -548,11 +568,12 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -1181,16 +1202,19 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), _foo1) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1203,12 +1227,13 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -1226,12 +1251,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1244,12 +1271,13 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -1267,12 +1295,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1285,12 +1315,13 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -1308,12 +1339,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1326,12 +1359,13 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -1349,12 +1383,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1367,12 +1403,13 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -1390,12 +1427,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1408,12 +1447,13 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -1431,12 +1471,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1449,12 +1491,13 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -1472,12 +1515,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1490,12 +1535,13 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -1513,12 +1559,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1531,12 +1579,13 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -1554,12 +1603,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1572,12 +1623,13 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -1595,12 +1647,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1613,12 +1667,13 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -1636,12 +1691,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1654,12 +1711,13 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -1677,12 +1735,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1695,12 +1755,13 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -1718,12 +1779,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1736,12 +1799,13 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) @@ -1759,12 +1823,14 @@ class BasicAtomicPointerTests: XCTestCase { let v: UnsafeAtomic> = .create(_foo1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( - expected: _foo1, - desired: _foo2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafePointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo1) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) @@ -1777,12 +1843,13 @@ class BasicAtomicPointerTests: XCTestCase { XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo2) - (exchanged, original) = v.weakCompareExchange( - expected: _foo2, - desired: _foo1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _foo2) XCTAssertEqual(v.load(ordering: .relaxed), _foo1) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicRawPointerTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicRawPointerTests.swift index 157ea7e..87ca1df 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicRawPointerTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicRawPointerTests.swift @@ -369,15 +369,19 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), _raw1) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -389,11 +393,12 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -410,11 +415,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -426,11 +434,12 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -447,11 +456,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -463,11 +475,12 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -484,11 +497,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -500,11 +516,12 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -521,11 +538,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -537,11 +557,12 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -1170,16 +1191,19 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), _raw1) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1192,12 +1216,13 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -1215,12 +1240,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1233,12 +1260,13 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -1256,12 +1284,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1274,12 +1304,13 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -1297,12 +1328,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1315,12 +1348,13 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -1338,12 +1372,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1356,12 +1392,13 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -1379,12 +1416,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1397,12 +1436,13 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -1420,12 +1460,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1438,12 +1480,13 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -1461,12 +1504,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1479,12 +1524,13 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -1502,12 +1548,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1520,12 +1568,13 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -1543,12 +1592,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1561,12 +1612,13 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -1584,12 +1636,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1602,12 +1656,13 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -1625,12 +1680,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1643,12 +1700,13 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -1666,12 +1724,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1684,12 +1744,13 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -1707,12 +1768,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1725,12 +1788,13 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) @@ -1748,12 +1812,14 @@ class BasicAtomicRawPointerTests: XCTestCase { let v: UnsafeAtomic = .create(_raw1) defer { v.destroy() } - var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( - expected: _raw1, - desired: _raw2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UnsafeRawPointer) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw1) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) @@ -1766,12 +1832,13 @@ class BasicAtomicRawPointerTests: XCTestCase { XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw2) - (exchanged, original) = v.weakCompareExchange( - expected: _raw2, - desired: _raw1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _raw2) XCTAssertEqual(v.load(ordering: .relaxed), _raw1) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicRawRepresentableTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicRawRepresentableTests.swift index fc0dcd6..2677efa 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicRawRepresentableTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicRawRepresentableTests.swift @@ -359,15 +359,19 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -379,11 +383,12 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -400,11 +405,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -416,11 +424,12 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -437,11 +446,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -453,11 +465,12 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -474,11 +487,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -490,11 +506,12 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -511,11 +528,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -527,11 +547,12 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -1160,16 +1181,19 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -1182,12 +1206,13 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -1205,12 +1230,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -1223,12 +1250,13 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -1246,12 +1274,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -1264,12 +1294,13 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -1287,12 +1318,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -1305,12 +1338,13 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -1328,12 +1362,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -1346,12 +1382,13 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -1369,12 +1406,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -1387,12 +1426,13 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -1410,12 +1450,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -1428,12 +1470,13 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -1451,12 +1494,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -1469,12 +1514,13 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -1492,12 +1538,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -1510,12 +1558,13 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -1533,12 +1582,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -1551,12 +1602,13 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -1574,12 +1626,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -1592,12 +1646,13 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -1615,12 +1670,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -1633,12 +1690,13 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -1656,12 +1714,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -1674,12 +1734,13 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -1697,12 +1758,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -1715,12 +1778,13 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) @@ -1738,12 +1802,14 @@ class BasicAtomicRawRepresentableTests: XCTestCase { let v: UnsafeAtomic = .create(Fred.one) defer { v.destroy() } - var (exchanged, original): (Bool, Fred) = v.weakCompareExchange( - expected: Fred.one, - desired: Fred.two, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Fred) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Fred.one) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) @@ -1756,12 +1822,13 @@ class BasicAtomicRawRepresentableTests: XCTestCase { XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) - (exchanged, original) = v.weakCompareExchange( - expected: Fred.two, - desired: Fred.one, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, Fred.two) XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicReferenceTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicReferenceTests.swift index 65883e0..0ce7900 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicReferenceTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicReferenceTests.swift @@ -361,15 +361,19 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), _baz1) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -381,11 +385,12 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -402,11 +407,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -418,11 +426,12 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -439,11 +448,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -455,11 +467,12 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -476,11 +489,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -492,11 +508,12 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -513,11 +530,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -529,11 +549,12 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -1162,16 +1183,19 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), _baz1) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1184,12 +1208,13 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -1207,12 +1232,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1225,12 +1252,13 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -1248,12 +1276,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1266,12 +1296,13 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -1289,12 +1320,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1307,12 +1340,13 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -1330,12 +1364,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1348,12 +1384,13 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -1371,12 +1408,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1389,12 +1428,13 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -1412,12 +1452,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1430,12 +1472,13 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -1453,12 +1496,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1471,12 +1516,13 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -1494,12 +1540,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1512,12 +1560,13 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -1535,12 +1584,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1553,12 +1604,13 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -1576,12 +1628,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1594,12 +1648,13 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -1617,12 +1672,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1635,12 +1692,13 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -1658,12 +1716,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1676,12 +1736,13 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -1699,12 +1760,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1717,12 +1780,13 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) @@ -1740,12 +1804,14 @@ class BasicAtomicReferenceTests: XCTestCase { let v: UnsafeAtomic = .create(_baz1) defer { v.destroy() } - var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( - expected: _baz1, - desired: _baz2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Baz) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz1) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) @@ -1758,12 +1824,13 @@ class BasicAtomicReferenceTests: XCTestCase { XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz2) - (exchanged, original) = v.weakCompareExchange( - expected: _baz2, - desired: _baz1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _baz2) XCTAssertEqual(v.load(ordering: .relaxed), _baz1) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt16Tests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt16Tests.swift index cf233db..0a04807 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt16Tests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt16Tests.swift @@ -359,15 +359,19 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -379,11 +383,12 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -400,11 +405,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -416,11 +424,12 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -437,11 +446,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -453,11 +465,12 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -474,11 +487,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -490,11 +506,12 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -511,11 +528,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -527,11 +547,12 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1160,16 +1181,19 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1182,12 +1206,13 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1205,12 +1230,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1223,12 +1250,13 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1246,12 +1274,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1264,12 +1294,13 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1287,12 +1318,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1305,12 +1338,13 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1328,12 +1362,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1346,12 +1382,13 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1369,12 +1406,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1387,12 +1426,13 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1410,12 +1450,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1428,12 +1470,13 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1451,12 +1494,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1469,12 +1514,13 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1492,12 +1538,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1510,12 +1558,13 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1533,12 +1582,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1551,12 +1602,13 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1574,12 +1626,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1592,12 +1646,13 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1615,12 +1670,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1633,12 +1690,13 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1656,12 +1714,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1674,12 +1734,13 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1697,12 +1758,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1715,12 +1778,13 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1738,12 +1802,14 @@ class BasicAtomicUInt16Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt16) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1756,12 +1822,13 @@ class BasicAtomicUInt16Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt32Tests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt32Tests.swift index a62d823..dd7bac3 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt32Tests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt32Tests.swift @@ -359,15 +359,19 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -379,11 +383,12 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -400,11 +405,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -416,11 +424,12 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -437,11 +446,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -453,11 +465,12 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -474,11 +487,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -490,11 +506,12 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -511,11 +528,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -527,11 +547,12 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1160,16 +1181,19 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1182,12 +1206,13 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1205,12 +1230,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1223,12 +1250,13 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1246,12 +1274,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1264,12 +1294,13 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1287,12 +1318,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1305,12 +1338,13 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1328,12 +1362,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1346,12 +1382,13 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1369,12 +1406,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1387,12 +1426,13 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1410,12 +1450,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1428,12 +1470,13 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1451,12 +1494,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1469,12 +1514,13 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1492,12 +1538,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1510,12 +1558,13 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1533,12 +1582,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1551,12 +1602,13 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1574,12 +1626,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1592,12 +1646,13 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1615,12 +1670,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1633,12 +1690,13 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1656,12 +1714,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1674,12 +1734,13 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1697,12 +1758,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1715,12 +1778,13 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1738,12 +1802,14 @@ class BasicAtomicUInt32Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt32) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1756,12 +1822,13 @@ class BasicAtomicUInt32Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt64Tests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt64Tests.swift index 4dfd806..ed88c36 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt64Tests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt64Tests.swift @@ -359,15 +359,19 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -379,11 +383,12 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -400,11 +405,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -416,11 +424,12 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -437,11 +446,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -453,11 +465,12 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -474,11 +487,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -490,11 +506,12 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -511,11 +528,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -527,11 +547,12 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1160,16 +1181,19 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1182,12 +1206,13 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1205,12 +1230,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1223,12 +1250,13 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1246,12 +1274,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1264,12 +1294,13 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1287,12 +1318,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1305,12 +1338,13 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1328,12 +1362,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1346,12 +1382,13 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1369,12 +1406,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1387,12 +1426,13 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1410,12 +1450,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1428,12 +1470,13 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1451,12 +1494,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1469,12 +1514,13 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1492,12 +1538,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1510,12 +1558,13 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1533,12 +1582,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1551,12 +1602,13 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1574,12 +1626,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1592,12 +1646,13 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1615,12 +1670,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1633,12 +1690,13 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1656,12 +1714,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1674,12 +1734,13 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1697,12 +1758,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1715,12 +1778,13 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1738,12 +1802,14 @@ class BasicAtomicUInt64Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt64) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1756,12 +1822,13 @@ class BasicAtomicUInt64Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt8Tests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt8Tests.swift index ca8ecc9..af7bf01 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt8Tests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt8Tests.swift @@ -359,15 +359,19 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -379,11 +383,12 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -400,11 +405,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -416,11 +424,12 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -437,11 +446,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -453,11 +465,12 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -474,11 +487,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -490,11 +506,12 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -511,11 +528,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -527,11 +547,12 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1160,16 +1181,19 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1182,12 +1206,13 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1205,12 +1230,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1223,12 +1250,13 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1246,12 +1274,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1264,12 +1294,13 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1287,12 +1318,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1305,12 +1338,13 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1328,12 +1362,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1346,12 +1382,13 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1369,12 +1406,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1387,12 +1426,13 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1410,12 +1450,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1428,12 +1470,13 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1451,12 +1494,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1469,12 +1514,13 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1492,12 +1538,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1510,12 +1558,13 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1533,12 +1582,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1551,12 +1602,13 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1574,12 +1626,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1592,12 +1646,13 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1615,12 +1670,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1633,12 +1690,13 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1656,12 +1714,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1674,12 +1734,13 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1697,12 +1758,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1715,12 +1778,13 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1738,12 +1802,14 @@ class BasicAtomicUInt8Tests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt8) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1756,12 +1822,13 @@ class BasicAtomicUInt8Tests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUIntTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUIntTests.swift index 067adcb..58eaf90 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUIntTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUIntTests.swift @@ -359,15 +359,19 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -379,11 +383,12 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -400,11 +405,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -416,11 +424,12 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -437,11 +446,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -453,11 +465,12 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -474,11 +487,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -490,11 +506,12 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -511,11 +528,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -527,11 +547,12 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1160,16 +1181,19 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), 12) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1182,12 +1206,13 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1205,12 +1230,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1223,12 +1250,13 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1246,12 +1274,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1264,12 +1294,13 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1287,12 +1318,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1305,12 +1338,13 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1328,12 +1362,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1346,12 +1382,13 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1369,12 +1406,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1387,12 +1426,13 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1410,12 +1450,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1428,12 +1470,13 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1451,12 +1494,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1469,12 +1514,13 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1492,12 +1538,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1510,12 +1558,13 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1533,12 +1582,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1551,12 +1602,13 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1574,12 +1626,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1592,12 +1646,13 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1615,12 +1670,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1633,12 +1690,13 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1656,12 +1714,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1674,12 +1734,13 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1697,12 +1758,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1715,12 +1778,13 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) @@ -1738,12 +1802,14 @@ class BasicAtomicUIntTests: XCTestCase { let v: UnsafeAtomic = .create(12) defer { v.destroy() } - var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( - expected: 12, - desired: 23, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, UInt) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 12) XCTAssertEqual(v.load(ordering: .relaxed), 23) @@ -1756,12 +1822,13 @@ class BasicAtomicUIntTests: XCTestCase { XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 23) - (exchanged, original) = v.weakCompareExchange( - expected: 23, - desired: 12, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, 23) XCTAssertEqual(v.load(ordering: .relaxed), 12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUnmanagedTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUnmanagedTests.swift index 35d846b..eb8e76d 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUnmanagedTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUnmanagedTests.swift @@ -366,15 +366,19 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), _bar1) } + func test_weakCompareExchange_relaxed() { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - ordering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -386,11 +390,12 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - ordering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + ordering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -407,11 +412,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - ordering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -423,11 +431,12 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - ordering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + ordering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -444,11 +453,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - ordering: .releasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -460,11 +472,12 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - ordering: .releasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + ordering: .releasing) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -481,11 +494,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -497,11 +513,12 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - ordering: .acquiringAndReleasing) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + ordering: .acquiringAndReleasing) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -518,11 +535,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -534,11 +554,12 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - ordering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + ordering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -1167,16 +1188,19 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), _bar1) } + func test_weakCompareExchange_relaxed_relaxed() { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1189,12 +1213,13 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - successOrdering: .relaxed, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + successOrdering: .relaxed, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -1212,12 +1237,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1230,12 +1257,13 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - successOrdering: .relaxed, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + successOrdering: .relaxed, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -1253,12 +1281,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1271,12 +1301,13 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - successOrdering: .relaxed, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + successOrdering: .relaxed, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -1294,12 +1325,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1312,12 +1345,13 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - successOrdering: .acquiring, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + successOrdering: .acquiring, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -1335,12 +1369,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1353,12 +1389,13 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - successOrdering: .acquiring, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + successOrdering: .acquiring, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -1376,12 +1413,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1394,12 +1433,13 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - successOrdering: .acquiring, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + successOrdering: .acquiring, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -1417,12 +1457,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1435,12 +1477,13 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - successOrdering: .releasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + successOrdering: .releasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -1458,12 +1501,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1476,12 +1521,13 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - successOrdering: .releasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + successOrdering: .releasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -1499,12 +1545,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1517,12 +1565,13 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - successOrdering: .releasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + successOrdering: .releasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -1540,12 +1589,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1558,12 +1609,13 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -1581,12 +1633,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1599,12 +1653,13 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -1622,12 +1677,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1640,12 +1697,13 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - successOrdering: .acquiringAndReleasing, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + successOrdering: .acquiringAndReleasing, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -1663,12 +1721,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1681,12 +1741,13 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .relaxed) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .relaxed) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -1704,12 +1765,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1722,12 +1785,13 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .acquiring) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .acquiring) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) @@ -1745,12 +1809,14 @@ class BasicAtomicUnmanagedTests: XCTestCase { let v: UnsafeAtomic> = .create(_bar1) defer { v.destroy() } - var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( - expected: _bar1, - desired: _bar2, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + var (exchanged, original): (Bool, Unmanaged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar1) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) @@ -1763,12 +1829,13 @@ class BasicAtomicUnmanagedTests: XCTestCase { XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar2) - (exchanged, original) = v.weakCompareExchange( - expected: _bar2, - desired: _bar1, - successOrdering: .sequentiallyConsistent, - failureOrdering: .sequentiallyConsistent) - XCTAssertTrue(exchanged) + repeat { + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + successOrdering: .sequentiallyConsistent, + failureOrdering: .sequentiallyConsistent) + } while !exchanged XCTAssertEqual(original, _bar2) XCTAssertEqual(v.load(ordering: .relaxed), _bar1) diff --git a/Utilities/run-full-tests.sh b/Utilities/run-full-tests.sh index 26bba77..1239850 100755 --- a/Utilities/run-full-tests.sh +++ b/Utilities/run-full-tests.sh @@ -116,7 +116,7 @@ if [ "$(uname)" = "Darwin" ]; then try_xcodeproj "xcodeproj.build.macOS" "generic/platform=macOS" -project Xcode/Atomics.xcodeproj -scheme Atomics build try_xcodeproj "xcodeproj.build.iOS" "generic/platform=iOS" -project Xcode/Atomics.xcodeproj -scheme Atomics build try_xcodeproj "xcodeproj.build.watchOS" "generic/platform=watchOS" -project Xcode/Atomics.xcodeproj -scheme Atomics build - try_xcodeproj "xcodeproj.build.watchOS" "generic/platform=tvOS" -project Xcode/Atomics.xcodeproj -scheme Atomics build + try_xcodeproj "xcodeproj.build.tvOS" "generic/platform=tvOS" -project Xcode/Atomics.xcodeproj -scheme Atomics build fi # Build with custom configurations diff --git a/Xcode/Atomics.xcconfig b/Xcode/Atomics.xcconfig index 0f40efc..7bb0aee 100644 --- a/Xcode/Atomics.xcconfig +++ b/Xcode/Atomics.xcconfig @@ -39,6 +39,3 @@ ENABLE_TESTABILITY = NO ENABLE_TESTABILITY[config=Debug] = YES GENERATE_INFOPLIST_FILE = YES - -CODE_SIGN_STYLE = Automatic -CODE_SIGN_IDENTITY = - diff --git a/Xcode/Atomics.xcodeproj/project.pbxproj b/Xcode/Atomics.xcodeproj/project.pbxproj index 262e011..fdcb43f 100644 --- a/Xcode/Atomics.xcodeproj/project.pbxproj +++ b/Xcode/Atomics.xcodeproj/project.pbxproj @@ -3,7 +3,7 @@ archiveVersion = 1; classes = { }; - objectVersion = 56; + objectVersion = 60; objects = { /* Begin PBXBuildFile section */ @@ -198,7 +198,6 @@ 7DA9B46E2ABBD93D00F14CE3 /* PointerConformances.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PointerConformances.swift; sourceTree = ""; }; 7DA9B46F2ABBD93D00F14CE3 /* AtomicBool.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AtomicBool.swift; sourceTree = ""; }; 7DF2275B2ABCBF4B00EC2AFE /* Package@swift-5.7.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Package@swift-5.7.swift"; path = "../Package@swift-5.7.swift"; sourceTree = ""; }; - 7DF2275C2ABCBF4B00EC2AFE /* Package@swift-5.6.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Package@swift-5.6.swift"; path = "../Package@swift-5.6.swift"; sourceTree = ""; }; 7DF2275D2ABCBF4B00EC2AFE /* Package@swift-5.8.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = "Package@swift-5.8.swift"; path = "../Package@swift-5.8.swift"; sourceTree = ""; }; BB63DC6A29D782010054E9C2 /* Atomics.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = Atomics.xctestplan; sourceTree = ""; }; /* End PBXFileReference section */ @@ -226,7 +225,6 @@ isa = PBXGroup; children = ( 7D489EC529CE96DA00499B21 /* Package.swift */, - 7DF2275C2ABCBF4B00EC2AFE /* Package@swift-5.6.swift */, 7DF2275B2ABCBF4B00EC2AFE /* Package@swift-5.7.swift */, 7DF2275D2ABCBF4B00EC2AFE /* Package@swift-5.8.swift */, 7D489EC629CE96DA00499B21 /* CMakeLists.txt */, @@ -241,6 +239,7 @@ 7D489E4029CE969D00499B21 /* Products */, ); sourceTree = ""; + tabWidth = 8; }; 7D489E4029CE969D00499B21 /* Products */ = { isa = PBXGroup; @@ -591,7 +590,7 @@ }; }; buildConfigurationList = 7D489E3929CE969D00499B21 /* Build configuration list for PBXProject "Atomics" */; - compatibilityVersion = "Xcode 14.0"; + compatibilityVersion = "Xcode 15.0"; developmentRegion = en; hasScannedForEncodings = 0; knownRegions = ( diff --git a/Xcode/AtomicsTests.xcconfig b/Xcode/AtomicsTests.xcconfig index 80c4fc1..934be2f 100644 --- a/Xcode/AtomicsTests.xcconfig +++ b/Xcode/AtomicsTests.xcconfig @@ -20,8 +20,4 @@ MARKETING_VERSION = 1.0 GENERATE_INFOPLIST_FILE = YES -CODE_SIGN_STYLE = Automatic -CODE_SIGN_IDENTITY = - - ENABLE_TESTABILITY = NO - diff --git a/Xcode/Shared.xcconfig b/Xcode/Shared.xcconfig index c8538a2..9968527 100644 --- a/Xcode/Shared.xcconfig +++ b/Xcode/Shared.xcconfig @@ -11,6 +11,12 @@ SDKROOT = macosx +CODE_SIGN_STYLE = Automatic +CODE_SIGN_IDENTITY = - +CODE_SIGN_IDENTITY[sdk=iphoneos*] = "iOS Developer" +CODE_SIGN_IDENTITY[sdk=watchos*] = "iOS Developer" +CODE_SIGN_IDENTITY[sdk=appletvos*] = "iOS Developer" + SWIFT_VERSION = 5.5 ONLY_ACTIVE_ARCH[config=Debug] = YES