Skip to content

Commit 02adf95

Browse files
authored
Merge pull request #78799 from lorentey/note-cas-loops
[doc] Atomic.add, .subtract: Add note on atomic codegen
2 parents 48f6f24 + d52ed4c commit 02adf95

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

stdlib/public/Synchronization/Atomics/AtomicIntegers.swift.gyb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@ extension Atomic where Value == ${intType} {
163163
/// overflow does occur. In `-Ounchecked` builds, overflow checking is not
164164
/// performed.
165165
///
166+
/// The need to check for overflow means that this operation is typically
167+
/// compiled into a compare-exchange loop. For use cases that require a
168+
/// direct atomic addition, see the `wrappingAdd` operation: it avoids the
169+
/// loop, but in exchange it allows silent wraps on overflow.
170+
///
166171
/// - Parameter operand: An integer value.
167172
/// - Parameter ordering: The memory ordering to apply on this operation.
168173
/// - Returns: A tuple containing the original value before the operation and
@@ -202,6 +207,11 @@ extension Atomic where Value == ${intType} {
202207
/// overflow does occur. In `-Ounchecked` builds, overflow checking is not
203208
/// performed.
204209
///
210+
/// The need to check for overflow means that this operation is typically
211+
/// compiled into a compare-exchange loop. For use cases that require a
212+
/// direct atomic subtraction, see the `wrappingSubtract` operation: it
213+
/// avoids the loop, but in exchange it allows silent wraps on overflow.
214+
///
205215
/// - Parameter operand: An integer value.
206216
/// - Parameter ordering: The memory ordering to apply on this operation.
207217
/// - Returns: A tuple containing the original value before the operation and

0 commit comments

Comments
 (0)