Atomic
An encapsulation of an atomic primitive object.
atomics.swift:190This declaration is deprecated: please use ManagedAtomic from https://github.com/apple/swift-atomics instead
final class Atomic<T> where T : AtomicPrimitive
Atomic objects support a wide range of atomic operations:
Compare and swap
Add
Subtract
Exchange
Load current value
Store current value
Atomic primitives are useful when building constructs that need to communicate or cooperate across multiple threads. In the case of SwiftNIO this usually involves communicating across multiple event loops.
By necessity, all atomic values are references: after all, it makes no sense to talk about managing an atomic value when each time it’s modified the thread that modified it gets a local copy!
Citizens in NIOConcurrencyHelpers
Type members
Show obsolete interfaces (1)
Hide obsolete interfaces
init(value: T
) Create an atomic object with
value
.
Instance members
Show obsolete interfaces (6)
Hide obsolete interfaces
func add(T
) -> T Atomically adds
rhs
to this object.func compareAndExchange(expected: T, desired: T
) -> Bool Atomically compares the value against
expected
and, if they are equal, replaces the value withdesired
.func exchange(with: T
) -> T Atomically exchanges
value
for the current value of this object.func load(
) -> T Atomically loads and returns the value of this object.
func store(T
) Atomically replaces the value of this object with
value
.func sub(T
) -> T Atomically subtracts
rhs
from this object.
Citizens in NIOConcurrencyHelpers
where T:AtomicPrimitive, T:Sendable
Conformances
protocol Sendable
A type whose values can safely be passed across concurrency domains by copying.