UnsafeEmbeddedAtomic

An atomic primitive object.

atomics.swift:66

This declaration is deprecated: please use UnsafeAtomic from https://github.com/apple/swift-atomics instead

struct UnsafeEmbeddedAtomic<T> where T : AtomicPrimitive

Before using UnsafeEmbeddedAtomic, please consider whether your needs can be met by Atomic instead. UnsafeEmbeddedAtomic is a value type, but atomics are heap-allocated. Thus, it is only safe to use UnsafeEmbeddedAtomic in situations where the atomic can be guaranteed to be cleaned up (via calling destroy). If you cannot make these guarantees, use Atomic instead, which manages this for you.

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.