Instance Methodswift-nio 2.72.0NIOConcurrencyHelpers
compareAndExchange(expected:desired:)
Atomically compares the value against expected
and, if they are equal, replaces the value with desired
.
This declaration is deprecated: please use ManagedAtomic from https://github.com/apple/swift-atomics instead
func compareAndExchange(expected: T, desired: T) -> Bool
Parameters
Returns
True
if the exchange occurred, or False
if expected
did not match the current value and so no exchange occurred.
This implementation conforms to C11’s atomic_compare_exchange_strong
. This means that the compare-and-swap will always succeed if expected
is equal to value. Additionally, it uses a sequentially consistent ordering. For more details on atomic memory models, check the documentation for C11’s stdatomic.h
.
Other members in extension
Type members
Show obsolete interfaces (1)
Hide obsolete interfaces
static func makeAtomic(value: T
) -> NIOAtomic Create an atomic object with
value
Instance members
Show obsolete interfaces (5)
Hide obsolete interfaces
func add(T
) -> T Atomically adds
rhs
to this object.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.