Implements atomic values which can be safely updated across threads. More...
|
Data Structures | |
| struct | sys_atomic_t |
| Underlying atomic uint32_t value. More... | |
Typedefs | |
| typedef struct sys_atomic_t | sys_atomic_t |
| Underlying atomic uint32_t value. More... | |
Functions | |
| static void | sys_atomic_init (sys_atomic_t *a, uint32_t initial) |
| Initialize an atomic with an initial value. More... | |
| static uint32_t | sys_atomic_get (const sys_atomic_t *a) |
| Load the current value atomically. More... | |
| static void | sys_atomic_set (sys_atomic_t *a, uint32_t v) |
| Store a new value atomically. More... | |
| static uint32_t | sys_atomic_inc (sys_atomic_t *a) |
| Atomically increment and return the new value. More... | |
| static uint32_t | sys_atomic_dec (sys_atomic_t *a) |
| Atomically decrement and return the new value. More... | |
| static void | sys_atomic_set_bits (sys_atomic_t *a, uint32_t mask) |
| Atomically set bits (OR with mask). More... | |
| static void | sys_atomic_clear_bits (sys_atomic_t *a, uint32_t mask) |
| Atomically clear bits (AND with ~mask). More... | |
Implements atomic values which can be safely updated across threads.
This API allows you to maintain a uint32_t value across threads safely. The operations are to get, set, increment and decrement. For the increment and decrement operations return the new value.
| typedef struct sys_atomic_t sys_atomic_t |
Underlying atomic uint32_t value.
Do not access the value directly; use the sys_atomic_* APIs. in order to maintain thread safety.
|
inlinestatic |
Atomically clear bits (AND with ~mask).
| a | Pointer to the atomic value (must be non-NULL). |
| mask | Bit mask of bits to clear. |
Performs a relaxed fetch-and with the complement of mask; no ordering is implied.
Definition at line 136 of file atomic.h.
|
inlinestatic |
Atomically decrement and return the new value.
| a | Pointer to the atomic value (must be non-NULL). |
This uses relaxed ordering and wraps modulo 2^32.
Definition at line 109 of file atomic.h.
|
inlinestatic |
Load the current value atomically.
| a | Pointer to the atomic value (must be non-NULL). |
This is a relaxed load; it does not establish synchronization with other memory operations. If you need acquire semantics, introduce an explicit fence in the caller.
Definition at line 69 of file atomic.h.
|
inlinestatic |
Atomically increment and return the new value.
| a | Pointer to the atomic value (must be non-NULL). |
This uses relaxed ordering and wraps modulo 2^32.
Definition at line 96 of file atomic.h.
|
inlinestatic |
Initialize an atomic with an initial value.
| a | Pointer to the atomic value to initialize (must be non-NULL). |
| initial | The initial 32-bit value to store. |
This performs a relaxed store; it does not impose ordering with other memory operations. Use only as an initialization step before the atomic is shared with other threads.
Definition at line 54 of file atomic.h.
|
inlinestatic |
Store a new value atomically.
| a | Pointer to the atomic value (must be non-NULL). |
| v | The value to store. |
This is a relaxed store; it does not order or publish other writes. If you need release semantics, introduce an explicit fence in the caller.
Definition at line 83 of file atomic.h.
|
inlinestatic |
Atomically set bits (OR with mask).
| a | Pointer to the atomic value (must be non-NULL). |
| mask | Bit mask of bits to set. |
Performs a relaxed fetch-or; no ordering is implied.
Definition at line 122 of file atomic.h.