From 0f07d9dcf82fdd129ddad677ad381c23d37f530d Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Fri, 24 Mar 2023 16:30:14 -0700 Subject: [PATCH 1/2] Add a weakCompareExchange variant that only takes a single ordering Resolves https://github.com/apple/swift-atomics/issues/75 --- Package.swift | 9 +- Sources/Atomics/AtomicMemoryOrderings.swift | 18 ++ Sources/Atomics/AtomicStrongReference.swift | 2 + Sources/Atomics/AtomicValue.swift | 71 +++++++ Sources/Atomics/HighLevelTypes.swift.gyb | 40 ++++ .../autogenerated/HighLevelTypes.swift | 80 ++++++++ .../Basics/BasicTests.gyb-template | 14 +- .../autogenerated/BasicAtomicBoolTests.swift | 185 ++++++++++++++++++ .../BasicAtomicDoubleWordTests.swift | 185 ++++++++++++++++++ .../autogenerated/BasicAtomicInt16Tests.swift | 185 ++++++++++++++++++ .../autogenerated/BasicAtomicInt32Tests.swift | 185 ++++++++++++++++++ .../autogenerated/BasicAtomicInt64Tests.swift | 185 ++++++++++++++++++ .../autogenerated/BasicAtomicInt8Tests.swift | 185 ++++++++++++++++++ .../autogenerated/BasicAtomicIntTests.swift | 185 ++++++++++++++++++ .../BasicAtomicMutablePointerTests.swift | 185 ++++++++++++++++++ .../BasicAtomicMutableRawPointerTests.swift | 185 ++++++++++++++++++ ...sicAtomicOptionalMutablePointerTests.swift | 185 ++++++++++++++++++ ...AtomicOptionalMutableRawPointerTests.swift | 185 ++++++++++++++++++ .../BasicAtomicOptionalPointerTests.swift | 185 ++++++++++++++++++ .../BasicAtomicOptionalRawPointerTests.swift | 185 ++++++++++++++++++ ...cAtomicOptionalRawRepresentableTests.swift | 185 ++++++++++++++++++ .../BasicAtomicOptionalReferenceTests.swift | 185 ++++++++++++++++++ .../BasicAtomicOptionalUnmanagedTests.swift | 185 ++++++++++++++++++ .../BasicAtomicPointerTests.swift | 185 ++++++++++++++++++ .../BasicAtomicRawPointerTests.swift | 185 ++++++++++++++++++ .../BasicAtomicRawRepresentableTests.swift | 185 ++++++++++++++++++ .../BasicAtomicReferenceTests.swift | 185 ++++++++++++++++++ .../BasicAtomicUInt16Tests.swift | 185 ++++++++++++++++++ .../BasicAtomicUInt32Tests.swift | 185 ++++++++++++++++++ .../BasicAtomicUInt64Tests.swift | 185 ++++++++++++++++++ .../autogenerated/BasicAtomicUInt8Tests.swift | 185 ++++++++++++++++++ .../autogenerated/BasicAtomicUIntTests.swift | 185 ++++++++++++++++++ .../BasicAtomicUnmanagedTests.swift | 185 ++++++++++++++++++ 33 files changed, 5034 insertions(+), 10 deletions(-) diff --git a/Package.swift b/Package.swift index cf8f845..b808274 100644 --- a/Package.swift +++ b/Package.swift @@ -50,12 +50,13 @@ let package = Package( dependencies: ["_AtomicsShims"], exclude: [ "CMakeLists.txt", - "Builtins.swift.gyb", - "HighLevelTypes.swift.gyb", - "PointerConformances.swift.gyb", - "IntegerConformances.swift.gyb", "AtomicBool.swift.gyb", "AtomicLazyReference.swift.gyb", + "HighLevelTypes.swift.gyb", + "IntegerConformances.swift.gyb", + "PointerConformances.swift.gyb", + "Primitives.native.swift.gyb", + "Primitives.shims.swift.gyb", ], cSettings: _cSettings, swiftSettings: _swiftSettings diff --git a/Sources/Atomics/AtomicMemoryOrderings.swift b/Sources/Atomics/AtomicMemoryOrderings.swift index c4fa94a..bbb97a4 100644 --- a/Sources/Atomics/AtomicMemoryOrderings.swift +++ b/Sources/Atomics/AtomicMemoryOrderings.swift @@ -289,6 +289,24 @@ extension AtomicUpdateOrdering: CustomStringConvertible { } } +extension AtomicLoadOrdering { + @_semantics("constant_evaluable") + @_semantics("atomics.requires_constant_orderings") + @_transparent @_alwaysEmitIntoClient + static func _failureOrdering( + for ordering: AtomicUpdateOrdering + ) -> AtomicLoadOrdering { + switch ordering { + case .relaxed: return .relaxed + case .acquiring: return .acquiring + case .releasing: return .relaxed + case .acquiringAndReleasing: return .acquiring + case .sequentiallyConsistent: return .sequentiallyConsistent + default: fatalError("Unsupported ordering") + } + } +} + /// Establishes a memory ordering without associating it with a /// particular atomic operation. /// diff --git a/Sources/Atomics/AtomicStrongReference.swift b/Sources/Atomics/AtomicStrongReference.swift index cc53349..56c9060 100644 --- a/Sources/Atomics/AtomicStrongReference.swift +++ b/Sources/Atomics/AtomicStrongReference.swift @@ -12,6 +12,8 @@ #if ATOMICS_NATIVE_BUILTINS import Swift +#else +import _AtomicsShims #endif /// A class type that supports atomic strong references. diff --git a/Sources/Atomics/AtomicValue.swift b/Sources/Atomics/AtomicValue.swift index 8c5e716..9213018 100644 --- a/Sources/Atomics/AtomicValue.swift +++ b/Sources/Atomics/AtomicValue.swift @@ -176,6 +176,43 @@ public protocol AtomicStorage { failureOrdering: AtomicLoadOrdering ) -> (exchanged: Bool, original: Value) + /// Perform an atomic weak compare and exchange operation on the value + /// referenced by `pointer`, applying the specified memory orderings. + /// This compare-exchange variant is allowed to spuriously fail; it + /// is designed to be called in a loop until it indicates a successful + /// exchange has happened. + /// + /// This operation performs the following algorithm as a single atomic + /// transaction: + /// + /// ``` + /// atomic(self) { currentValue in + /// let original = currentValue + /// guard original == expected else { return (false, original) } + /// currentValue = desired + /// return (true, original) + /// } + /// ``` + /// + /// (In this weak form, transient conditions may cause the `original == + /// expected` check to sometimes return false when the two values are in fact + /// the same.) + /// + /// - Parameter expected: The expected current value. + /// - Parameter desired: The desired new value. + /// - Parameter pointer: A memory location previously initialized with a value + /// returned by `prepareAtomicRepresentation(for:)`. + /// - Parameter ordering: The memory ordering to apply on this operation. + /// - Returns: A tuple `(exchanged, original)`, where `exchanged` is true if + /// the exchange was successful, and `original` is the original value. + @_semantics("atomics.requires_constant_orderings") + static func atomicWeakCompareExchange( + expected: Value, + desired: __owned Value, + at pointer: UnsafeMutablePointer, + ordering: AtomicUpdateOrdering + ) -> (exchanged: Bool, original: Value) + /// Perform an atomic weak compare and exchange operation on the value /// referenced by `pointer`, applying the specified success/failure memory /// orderings. This compare-exchange variant is allowed to spuriously fail; it @@ -221,3 +258,37 @@ public protocol AtomicStorage { failureOrdering: AtomicLoadOrdering ) -> (exchanged: Bool, original: Value) } + +extension AtomicStorage { + @_semantics("atomics.requires_constant_orderings") + @_transparent @_alwaysEmitIntoClient + public static func atomicCompareExchange( + expected: Value, + desired: __owned Value, + at pointer: UnsafeMutablePointer, + ordering: AtomicUpdateOrdering + ) -> (exchanged: Bool, original: Value) { + atomicCompareExchange( + expected: expected, + desired: desired, + at: pointer, + successOrdering: ordering, + failureOrdering: ._failureOrdering(for: ordering)) + } + + @_semantics("atomics.requires_constant_orderings") + @_transparent @_alwaysEmitIntoClient + public static func atomicWeakCompareExchange( + expected: Value, + desired: __owned Value, + at pointer: UnsafeMutablePointer, + ordering: AtomicUpdateOrdering + ) -> (exchanged: Bool, original: Value) { + atomicWeakCompareExchange( + expected: expected, + desired: desired, + at: pointer, + successOrdering: ordering, + failureOrdering: ._failureOrdering(for: ordering)) + } +} diff --git a/Sources/Atomics/HighLevelTypes.swift.gyb b/Sources/Atomics/HighLevelTypes.swift.gyb index 1c08860..a2796eb 100644 --- a/Sources/Atomics/HighLevelTypes.swift.gyb +++ b/Sources/Atomics/HighLevelTypes.swift.gyb @@ -247,6 +247,46 @@ extension ${type} { failureOrdering: failureOrdering) } + /// Perform an atomic weak compare and exchange operation on the current + /// value, applying the memory ordering. This compare-exchange variant is + /// allowed to spuriously fail; it is designed to be called in a loop until + /// it indicates a successful exchange has happened. + /// + /// This operation performs the following algorithm as a single atomic + /// transaction: + /// + /// ``` + /// atomic(self) { currentValue in + /// let original = currentValue + /// guard original == expected else { return (false, original) } + /// currentValue = desired + /// return (true, original) + /// } + /// ``` + /// + /// (In this weak form, transient conditions may cause the `original == + /// expected` check to sometimes return false when the two values are in fact + /// the same.) + /// + /// - Parameter expected: The expected current value. + /// - Parameter desired: The desired new value. + /// - Parameter ordering: The memory ordering to apply on this operation. + /// - Returns: A tuple `(exchanged, original)`, where `exchanged` is true if + /// the exchange was successful, and `original` is the original value. + @_semantics("atomics.requires_constant_orderings") + @_transparent @_alwaysEmitIntoClient + public func weakCompareExchange( + expected: Value, + desired: __owned Value, + ordering: AtomicUpdateOrdering + ) -> (exchanged: Bool, original: Value) { + _Storage.atomicWeakCompareExchange( + expected: expected, + desired: desired, + at: _ptr, + ordering: ordering) + } + /// Perform an atomic weak compare and exchange operation on the current /// value, applying the specified success/failure memory orderings. This /// compare-exchange variant is allowed to spuriously fail; it is designed to diff --git a/Sources/Atomics/autogenerated/HighLevelTypes.swift b/Sources/Atomics/autogenerated/HighLevelTypes.swift index e082b75..8a8d950 100644 --- a/Sources/Atomics/autogenerated/HighLevelTypes.swift +++ b/Sources/Atomics/autogenerated/HighLevelTypes.swift @@ -248,6 +248,46 @@ extension UnsafeAtomic { failureOrdering: failureOrdering) } + /// Perform an atomic weak compare and exchange operation on the current + /// value, applying the memory ordering. This compare-exchange variant is + /// allowed to spuriously fail; it is designed to be called in a loop until + /// it indicates a successful exchange has happened. + /// + /// This operation performs the following algorithm as a single atomic + /// transaction: + /// + /// ``` + /// atomic(self) { currentValue in + /// let original = currentValue + /// guard original == expected else { return (false, original) } + /// currentValue = desired + /// return (true, original) + /// } + /// ``` + /// + /// (In this weak form, transient conditions may cause the `original == + /// expected` check to sometimes return false when the two values are in fact + /// the same.) + /// + /// - Parameter expected: The expected current value. + /// - Parameter desired: The desired new value. + /// - Parameter ordering: The memory ordering to apply on this operation. + /// - Returns: A tuple `(exchanged, original)`, where `exchanged` is true if + /// the exchange was successful, and `original` is the original value. + @_semantics("atomics.requires_constant_orderings") + @_transparent @_alwaysEmitIntoClient + public func weakCompareExchange( + expected: Value, + desired: __owned Value, + ordering: AtomicUpdateOrdering + ) -> (exchanged: Bool, original: Value) { + _Storage.atomicWeakCompareExchange( + expected: expected, + desired: desired, + at: _ptr, + ordering: ordering) + } + /// Perform an atomic weak compare and exchange operation on the current /// value, applying the specified success/failure memory orderings. This /// compare-exchange variant is allowed to spuriously fail; it is designed to @@ -654,6 +694,46 @@ extension ManagedAtomic { failureOrdering: failureOrdering) } + /// Perform an atomic weak compare and exchange operation on the current + /// value, applying the memory ordering. This compare-exchange variant is + /// allowed to spuriously fail; it is designed to be called in a loop until + /// it indicates a successful exchange has happened. + /// + /// This operation performs the following algorithm as a single atomic + /// transaction: + /// + /// ``` + /// atomic(self) { currentValue in + /// let original = currentValue + /// guard original == expected else { return (false, original) } + /// currentValue = desired + /// return (true, original) + /// } + /// ``` + /// + /// (In this weak form, transient conditions may cause the `original == + /// expected` check to sometimes return false when the two values are in fact + /// the same.) + /// + /// - Parameter expected: The expected current value. + /// - Parameter desired: The desired new value. + /// - Parameter ordering: The memory ordering to apply on this operation. + /// - Returns: A tuple `(exchanged, original)`, where `exchanged` is true if + /// the exchange was successful, and `original` is the original value. + @_semantics("atomics.requires_constant_orderings") + @_transparent @_alwaysEmitIntoClient + public func weakCompareExchange( + expected: Value, + desired: __owned Value, + ordering: AtomicUpdateOrdering + ) -> (exchanged: Bool, original: Value) { + _Storage.atomicWeakCompareExchange( + expected: expected, + desired: desired, + at: _ptr, + ordering: ordering) + } + /// Perform an atomic weak compare and exchange operation on the current /// value, applying the specified success/failure memory orderings. This /// compare-exchange variant is allowed to spuriously fail; it is designed to diff --git a/Tests/AtomicsTests/Basics/BasicTests.gyb-template b/Tests/AtomicsTests/Basics/BasicTests.gyb-template index b49d04d..f03e9a3 100644 --- a/Tests/AtomicsTests/Basics/BasicTests.gyb-template +++ b/Tests/AtomicsTests/Basics/BasicTests.gyb-template @@ -125,12 +125,13 @@ class BasicAtomic${label}Tests: XCTestCase { % end -% for (order, _, _, _, _) in updateOrderings: - func test_compareExchange_${order}() { +% for operation in ["compareExchange", "weakCompareExchange"]: +% for (order, _, _, _, _) in updateOrderings: + func test_${operation}_${order}() { let v: UnsafeAtomic<${type}> = .create(${a}) defer { v.destroy() } - var (exchanged, original): (Bool, ${type}) = v.compareExchange( + var (exchanged, original): (Bool, ${type}) = v.${operation}( expected: ${a}, desired: ${b}, ordering: .${order}) @@ -138,7 +139,7 @@ class BasicAtomic${label}Tests: XCTestCase { XCTAssertEqual(original, ${a}) XCTAssertEqual(v.load(ordering: .relaxed), ${b}) - (exchanged, original) = v.compareExchange( + (exchanged, original) = v.${operation}( expected: ${a}, desired: ${b}, ordering: .${order}) @@ -146,7 +147,7 @@ class BasicAtomic${label}Tests: XCTestCase { XCTAssertEqual(original, ${b}) XCTAssertEqual(v.load(ordering: .relaxed), ${b}) - (exchanged, original) = v.compareExchange( + (exchanged, original) = v.${operation}( expected: ${b}, desired: ${a}, ordering: .${order}) @@ -154,7 +155,7 @@ class BasicAtomic${label}Tests: XCTestCase { XCTAssertEqual(original, ${b}) XCTAssertEqual(v.load(ordering: .relaxed), ${a}) - (exchanged, original) = v.compareExchange( + (exchanged, original) = v.${operation}( expected: ${b}, desired: ${a}, ordering: .${order}) @@ -163,6 +164,7 @@ class BasicAtomic${label}Tests: XCTestCase { XCTAssertEqual(v.load(ordering: .relaxed), ${a}) } +% end % end % for operation in ["compareExchange", "weakCompareExchange"]: diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicBoolTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicBoolTests.swift index 535270c..1d29b5d 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicBoolTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicBoolTests.swift @@ -359,6 +359,191 @@ 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) + XCTAssertEqual(original, true) + XCTAssertEqual(v.load(ordering: .relaxed), false) + + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, false) + XCTAssertEqual(v.load(ordering: .relaxed), false) + + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, false) + XCTAssertEqual(v.load(ordering: .relaxed), true) + + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, true) + XCTAssertEqual(v.load(ordering: .relaxed), true) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(true) + defer { v.destroy() } + + var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( + expected: true, + desired: false, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, true) + XCTAssertEqual(v.load(ordering: .relaxed), false) + + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, false) + XCTAssertEqual(v.load(ordering: .relaxed), false) + + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, false) + XCTAssertEqual(v.load(ordering: .relaxed), true) + + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, true) + XCTAssertEqual(v.load(ordering: .relaxed), true) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(true) + defer { v.destroy() } + + var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( + expected: true, + desired: false, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, true) + XCTAssertEqual(v.load(ordering: .relaxed), false) + + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, false) + XCTAssertEqual(v.load(ordering: .relaxed), false) + + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, false) + XCTAssertEqual(v.load(ordering: .relaxed), true) + + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, true) + XCTAssertEqual(v.load(ordering: .relaxed), true) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(true) + defer { v.destroy() } + + var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( + expected: true, + desired: false, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, true) + XCTAssertEqual(v.load(ordering: .relaxed), false) + + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, false) + XCTAssertEqual(v.load(ordering: .relaxed), false) + + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, false) + XCTAssertEqual(v.load(ordering: .relaxed), true) + + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, true) + XCTAssertEqual(v.load(ordering: .relaxed), true) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(true) + defer { v.destroy() } + + var (exchanged, original): (Bool, Bool) = v.weakCompareExchange( + expected: true, + desired: false, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, true) + XCTAssertEqual(v.load(ordering: .relaxed), false) + + (exchanged, original) = v.weakCompareExchange( + expected: true, + desired: false, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, false) + XCTAssertEqual(v.load(ordering: .relaxed), false) + + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, false) + XCTAssertEqual(v.load(ordering: .relaxed), true) + + (exchanged, original) = v.weakCompareExchange( + expected: false, + desired: true, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, true) + XCTAssertEqual(v.load(ordering: .relaxed), true) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(true) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicDoubleWordTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicDoubleWordTests.swift index 6fc84f6..a954037 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicDoubleWordTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicDoubleWordTests.swift @@ -359,6 +359,191 @@ 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) + XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) + XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) + + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + ordering: .relaxed) + XCTAssertFalse(exchanged) + 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) + XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) + XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) + + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) + XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) + } + + func test_weakCompareExchange_acquiring() { + 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) + XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) + XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) + + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + ordering: .acquiring) + XCTAssertFalse(exchanged) + 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) + XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) + XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) + + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) + XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) + } + + func test_weakCompareExchange_releasing() { + 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) + XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) + XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) + + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + ordering: .releasing) + XCTAssertFalse(exchanged) + 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) + XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) + XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) + + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) + XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + 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) + XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) + XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) + + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + 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) + XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) + XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) + + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) + XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + 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) + XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) + XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 50, second: 32)) + + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 100, second: 64), + desired: DoubleWord(first: 50, second: 32), + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + 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) + XCTAssertEqual(original, DoubleWord(first: 50, second: 32)) + XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) + + (exchanged, original) = v.weakCompareExchange( + expected: DoubleWord(first: 50, second: 32), + desired: DoubleWord(first: 100, second: 64), + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, DoubleWord(first: 100, second: 64)) + XCTAssertEqual(v.load(ordering: .relaxed), DoubleWord(first: 100, second: 64)) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(DoubleWord(first: 100, second: 64)) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt16Tests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt16Tests.swift index 823ca10..14851c0 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt16Tests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt16Tests.swift @@ -359,6 +359,191 @@ 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) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int16) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt32Tests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt32Tests.swift index b01a7bc..bba0dd0 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt32Tests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt32Tests.swift @@ -359,6 +359,191 @@ 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) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int32) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt64Tests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt64Tests.swift index b8f73f5..01ba1fc 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt64Tests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt64Tests.swift @@ -359,6 +359,191 @@ 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) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int64) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt8Tests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt8Tests.swift index 544d7a1..c10c2cd 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt8Tests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicInt8Tests.swift @@ -359,6 +359,191 @@ 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) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int8) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicIntTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicIntTests.swift index 4db5159..99fe2e9 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicIntTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicIntTests.swift @@ -359,6 +359,191 @@ 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) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, Int) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicMutablePointerTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicMutablePointerTests.swift index 7e3a7e9..24fe725 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicMutablePointerTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicMutablePointerTests.swift @@ -380,6 +380,191 @@ 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) + XCTAssertEqual(original, _mfoo1) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mfoo1) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic> = .create(_mfoo1) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mfoo1) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mfoo1) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic> = .create(_mfoo1) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mfoo1) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mfoo1) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic> = .create(_mfoo1) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mfoo1) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mfoo1) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic> = .create(_mfoo1) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeMutablePointer) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mfoo1) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo1, + desired: _mfoo2, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: _mfoo1, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mfoo1) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo1) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic> = .create(_mfoo1) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicMutableRawPointerTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicMutableRawPointerTests.swift index 2330757..ff6ba48 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicMutableRawPointerTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicMutableRawPointerTests.swift @@ -369,6 +369,191 @@ 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) + XCTAssertEqual(original, _mraw1) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mraw1) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(_mraw1) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mraw1) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mraw1) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(_mraw1) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mraw1) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mraw1) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(_mraw1) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mraw1) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mraw1) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(_mraw1) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeMutableRawPointer) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mraw1) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw1, + desired: _mraw2, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: _mraw1, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mraw1) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw1) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(_mraw1) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalMutablePointerTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalMutablePointerTests.swift index 169bb58..7cfcd32 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalMutablePointerTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalMutablePointerTests.swift @@ -380,6 +380,191 @@ 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) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic?> = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic?> = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic?> = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic?> = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeMutablePointer?) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mfoo2, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), _mfoo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mfoo2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _mfoo2, + desired: nil, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic?> = .create(nil) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalMutableRawPointerTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalMutableRawPointerTests.swift index a898146..1d92c5f 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalMutableRawPointerTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalMutableRawPointerTests.swift @@ -369,6 +369,191 @@ 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) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeMutableRawPointer?) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _mraw2, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), _mraw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _mraw2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _mraw2, + desired: nil, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(nil) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalPointerTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalPointerTests.swift index 353ed52..e1a91db 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalPointerTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalPointerTests.swift @@ -380,6 +380,191 @@ 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) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic?> = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic?> = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic?> = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic?> = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafePointer?) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _foo2, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: nil, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic?> = .create(nil) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalRawPointerTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalRawPointerTests.swift index 7cb4c35..dfc2403 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalRawPointerTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalRawPointerTests.swift @@ -369,6 +369,191 @@ 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) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeRawPointer?) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _raw2, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: nil, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(nil) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalRawRepresentableTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalRawRepresentableTests.swift index e3bd3a7..4ba56a6 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalRawRepresentableTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalRawRepresentableTests.swift @@ -359,6 +359,191 @@ 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) + XCTAssertEqual(original, Hyacinth.bucket) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, Hyacinth.bucket) + XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) + } + + func test_weakCompareExchange_acquiring() { + 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) + XCTAssertEqual(original, Hyacinth.bucket) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, Hyacinth.bucket) + XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) + } + + func test_weakCompareExchange_releasing() { + 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) + XCTAssertEqual(original, Hyacinth.bucket) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, Hyacinth.bucket) + XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + 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) + XCTAssertEqual(original, Hyacinth.bucket) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, Hyacinth.bucket) + XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + 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) + XCTAssertEqual(original, Hyacinth.bucket) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: Hyacinth.bucket, + desired: nil, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: Hyacinth.bucket, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, Hyacinth.bucket) + XCTAssertEqual(v.load(ordering: .relaxed), Hyacinth.bucket) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(Hyacinth.bucket) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalReferenceTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalReferenceTests.swift index f555502..e81b1a7 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalReferenceTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalReferenceTests.swift @@ -361,6 +361,191 @@ 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) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, Baz?) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _baz2, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: nil, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(nil) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalUnmanagedTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalUnmanagedTests.swift index e8bd1b9..f2950e6 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalUnmanagedTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicOptionalUnmanagedTests.swift @@ -366,6 +366,191 @@ 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) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic?> = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic?> = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic?> = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic?> = .create(nil) + defer { v.destroy() } + + var (exchanged, original): (Bool, Unmanaged?) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: nil, + desired: _bar2, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: nil, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, nil) + XCTAssertEqual(v.load(ordering: .relaxed), nil) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic?> = .create(nil) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicPointerTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicPointerTests.swift index b3193eb..ff13f90 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicPointerTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicPointerTests.swift @@ -380,6 +380,191 @@ 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) + XCTAssertEqual(original, _foo1) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), _foo1) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _foo1) + XCTAssertEqual(v.load(ordering: .relaxed), _foo1) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic> = .create(_foo1) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _foo1) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), _foo1) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _foo1) + XCTAssertEqual(v.load(ordering: .relaxed), _foo1) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic> = .create(_foo1) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _foo1) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), _foo1) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _foo1) + XCTAssertEqual(v.load(ordering: .relaxed), _foo1) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic> = .create(_foo1) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _foo1) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), _foo1) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _foo1) + XCTAssertEqual(v.load(ordering: .relaxed), _foo1) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic> = .create(_foo1) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafePointer) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _foo1) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo1, + desired: _foo2, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), _foo2) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _foo2) + XCTAssertEqual(v.load(ordering: .relaxed), _foo1) + + (exchanged, original) = v.weakCompareExchange( + expected: _foo2, + desired: _foo1, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _foo1) + XCTAssertEqual(v.load(ordering: .relaxed), _foo1) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic> = .create(_foo1) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicRawPointerTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicRawPointerTests.swift index 3e1cb34..ce7ccbb 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicRawPointerTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicRawPointerTests.swift @@ -369,6 +369,191 @@ 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) + XCTAssertEqual(original, _raw1) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), _raw1) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _raw1) + XCTAssertEqual(v.load(ordering: .relaxed), _raw1) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(_raw1) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _raw1) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), _raw1) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _raw1) + XCTAssertEqual(v.load(ordering: .relaxed), _raw1) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(_raw1) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _raw1) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), _raw1) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _raw1) + XCTAssertEqual(v.load(ordering: .relaxed), _raw1) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(_raw1) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _raw1) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), _raw1) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _raw1) + XCTAssertEqual(v.load(ordering: .relaxed), _raw1) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(_raw1) + defer { v.destroy() } + + var (exchanged, original): (Bool, UnsafeRawPointer) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _raw1) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw1, + desired: _raw2, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), _raw2) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _raw2) + XCTAssertEqual(v.load(ordering: .relaxed), _raw1) + + (exchanged, original) = v.weakCompareExchange( + expected: _raw2, + desired: _raw1, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _raw1) + XCTAssertEqual(v.load(ordering: .relaxed), _raw1) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(_raw1) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicRawRepresentableTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicRawRepresentableTests.swift index bfdd728..5ffa191 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicRawRepresentableTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicRawRepresentableTests.swift @@ -359,6 +359,191 @@ 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) + XCTAssertEqual(original, Fred.one) + XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) + + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + ordering: .relaxed) + XCTAssertFalse(exchanged) + 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) + XCTAssertEqual(original, Fred.two) + XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) + + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, Fred.one) + XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) + } + + func test_weakCompareExchange_acquiring() { + 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) + XCTAssertEqual(original, Fred.one) + XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) + + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + ordering: .acquiring) + XCTAssertFalse(exchanged) + 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) + XCTAssertEqual(original, Fred.two) + XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) + + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, Fred.one) + XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) + } + + func test_weakCompareExchange_releasing() { + 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) + XCTAssertEqual(original, Fred.one) + XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) + + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + ordering: .releasing) + XCTAssertFalse(exchanged) + 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) + XCTAssertEqual(original, Fred.two) + XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) + + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, Fred.one) + XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + 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) + XCTAssertEqual(original, Fred.one) + XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) + + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + 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) + XCTAssertEqual(original, Fred.two) + XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) + + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, Fred.one) + XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + 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) + XCTAssertEqual(original, Fred.one) + XCTAssertEqual(v.load(ordering: .relaxed), Fred.two) + + (exchanged, original) = v.weakCompareExchange( + expected: Fred.one, + desired: Fred.two, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + 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) + XCTAssertEqual(original, Fred.two) + XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) + + (exchanged, original) = v.weakCompareExchange( + expected: Fred.two, + desired: Fred.one, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, Fred.one) + XCTAssertEqual(v.load(ordering: .relaxed), Fred.one) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(Fred.one) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicReferenceTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicReferenceTests.swift index 763b10d..0677434 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicReferenceTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicReferenceTests.swift @@ -361,6 +361,191 @@ 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) + XCTAssertEqual(original, _baz1) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), _baz1) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _baz1) + XCTAssertEqual(v.load(ordering: .relaxed), _baz1) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(_baz1) + defer { v.destroy() } + + var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _baz1) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), _baz1) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _baz1) + XCTAssertEqual(v.load(ordering: .relaxed), _baz1) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(_baz1) + defer { v.destroy() } + + var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _baz1) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), _baz1) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _baz1) + XCTAssertEqual(v.load(ordering: .relaxed), _baz1) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(_baz1) + defer { v.destroy() } + + var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _baz1) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), _baz1) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _baz1) + XCTAssertEqual(v.load(ordering: .relaxed), _baz1) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(_baz1) + defer { v.destroy() } + + var (exchanged, original): (Bool, Baz) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _baz1) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz1, + desired: _baz2, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), _baz2) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _baz2) + XCTAssertEqual(v.load(ordering: .relaxed), _baz1) + + (exchanged, original) = v.weakCompareExchange( + expected: _baz2, + desired: _baz1, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _baz1) + XCTAssertEqual(v.load(ordering: .relaxed), _baz1) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(_baz1) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt16Tests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt16Tests.swift index e4b8bea..e89c489 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt16Tests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt16Tests.swift @@ -359,6 +359,191 @@ 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) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt16) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt32Tests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt32Tests.swift index 2051bb5..acd017d 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt32Tests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt32Tests.swift @@ -359,6 +359,191 @@ 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) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt32) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt64Tests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt64Tests.swift index 48e1e99..3281584 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt64Tests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt64Tests.swift @@ -359,6 +359,191 @@ 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) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt64) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt8Tests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt8Tests.swift index c043d34..ba0913c 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt8Tests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUInt8Tests.swift @@ -359,6 +359,191 @@ 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) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt8) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUIntTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUIntTests.swift index d451904..af6e3ec 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUIntTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUIntTests.swift @@ -359,6 +359,191 @@ 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) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic = .create(12) + defer { v.destroy() } + + var (exchanged, original): (Bool, UInt) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 12, + desired: 23, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 23) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, 23) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + + (exchanged, original) = v.weakCompareExchange( + expected: 23, + desired: 12, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, 12) + XCTAssertEqual(v.load(ordering: .relaxed), 12) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic = .create(12) diff --git a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUnmanagedTests.swift b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUnmanagedTests.swift index df8b793..0896295 100644 --- a/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUnmanagedTests.swift +++ b/Tests/AtomicsTests/Basics/autogenerated/BasicAtomicUnmanagedTests.swift @@ -366,6 +366,191 @@ 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) + XCTAssertEqual(original, _bar1) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + ordering: .relaxed) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), _bar1) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + ordering: .relaxed) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _bar1) + XCTAssertEqual(v.load(ordering: .relaxed), _bar1) + } + + func test_weakCompareExchange_acquiring() { + let v: UnsafeAtomic> = .create(_bar1) + defer { v.destroy() } + + var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _bar1) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + ordering: .acquiring) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), _bar1) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + ordering: .acquiring) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _bar1) + XCTAssertEqual(v.load(ordering: .relaxed), _bar1) + } + + func test_weakCompareExchange_releasing() { + let v: UnsafeAtomic> = .create(_bar1) + defer { v.destroy() } + + var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _bar1) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + ordering: .releasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), _bar1) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + ordering: .releasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _bar1) + XCTAssertEqual(v.load(ordering: .relaxed), _bar1) + } + + func test_weakCompareExchange_acquiringAndReleasing() { + let v: UnsafeAtomic> = .create(_bar1) + defer { v.destroy() } + + var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _bar1) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + ordering: .acquiringAndReleasing) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), _bar1) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + ordering: .acquiringAndReleasing) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _bar1) + XCTAssertEqual(v.load(ordering: .relaxed), _bar1) + } + + func test_weakCompareExchange_sequentiallyConsistent() { + let v: UnsafeAtomic> = .create(_bar1) + defer { v.destroy() } + + var (exchanged, original): (Bool, Unmanaged) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _bar1) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar1, + desired: _bar2, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), _bar2) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + ordering: .sequentiallyConsistent) + XCTAssertTrue(exchanged) + XCTAssertEqual(original, _bar2) + XCTAssertEqual(v.load(ordering: .relaxed), _bar1) + + (exchanged, original) = v.weakCompareExchange( + expected: _bar2, + desired: _bar1, + ordering: .sequentiallyConsistent) + XCTAssertFalse(exchanged) + XCTAssertEqual(original, _bar1) + XCTAssertEqual(v.load(ordering: .relaxed), _bar1) + } + func test_compareExchange_relaxed_relaxed() { let v: UnsafeAtomic> = .create(_bar1) From 11a0547baa79060bcf3f881f18346f1d6a28482a Mon Sep 17 00:00:00 2001 From: Karoy Lorentey Date: Fri, 24 Mar 2023 17:12:13 -0700 Subject: [PATCH 2/2] Update CMake configuration --- Sources/Atomics/CMakeLists.txt | 8 +++++--- Sources/CMakeLists.txt | 3 +-- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Sources/Atomics/CMakeLists.txt b/Sources/Atomics/CMakeLists.txt index 10df675..52c1233 100644 --- a/Sources/Atomics/CMakeLists.txt +++ b/Sources/Atomics/CMakeLists.txt @@ -13,14 +13,17 @@ add_library(Atomics autogenerated/HighLevelTypes.swift autogenerated/IntegerConformances.swift autogenerated/PointerConformances.swift + autogenerated/Primitives.native.swift + autogenerated/Primitives.shims.swift AtomicInteger.swift AtomicMemoryOrderings.swift AtomicOptional.swift - AtomicRawRepresentable.swift AtomicOptionalRawRepresentable.swift + AtomicRawRepresentable.swift AtomicStrongReference.swift AtomicValue.swift - DoubleWord.swift) + DoubleWord.swift + "Unmanaged extensions.swift") set_target_properties(Atomics PROPERTIES INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_Swift_MODULE_DIRECTORY}) if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") @@ -28,7 +31,6 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "x86_64|AMD64") "$<$:SHELL:-Xcc -mcx16>") endif() target_link_libraries(Atomics PUBLIC - _AtomicBuiltins _AtomicsShims) _install_target(Atomics) diff --git a/Sources/CMakeLists.txt b/Sources/CMakeLists.txt index 80ca444..3ab3324 100644 --- a/Sources/CMakeLists.txt +++ b/Sources/CMakeLists.txt @@ -1,12 +1,11 @@ #[[ This source file is part of the Swift Atomics Open Source Project -Copyright (c) 2021-2023 Apple Inc. and the Swift project authors +Copyright (c) 2021 - 2023 Apple Inc. and the Swift project authors Licensed under Apache License v2.0 with Runtime Library Exception See https://swift.org/LICENSE.txt for license information #]] add_subdirectory(_AtomicsShims) -add_subdirectory(_AtomicBuiltins) add_subdirectory(Atomics)