CX Framework
Cross-platform C utility framework
Loading...
Searching...
No Matches
CPU Operations

Cross-platform atomic operations, memory barriers, and CPU intrinsics. This module provides:

The implementation is selected at compile time based on the compiler:

Atomic Types: Use the atomic(type) macro to declare atomic variables:

atomic(int32) counter = 0;
atomic(ptr) pointer = NULL;

Memory Ordering:

Common Operations:

// Load and store
int32 val = atomicLoad(int32, &counter, Acquire);
atomicStore(&counter, 42, Release);
// Fetch and add
int32 old = atomicFetchAdd(&counter, 1, AcqRel);
// Compare and exchange
int32 expected = 0;
bool success = atomicCompareExchange(&counter, &expected, 1, AcqRel, Acquire);
// Exchange (atomic swap)
int32 prev = atomicExchange(&counter, 100, AcqRel);

See the compiler-specific headers for the complete API.