AWS IoT Device SDK C: Platform
Platform portability layer
Return to main page ↑
iot_atomic_generic.h File Reference

Generic implementation of atomic operations. More...

#include <stdint.h>
#include "iot_atomic.h"
#include "platform/iot_threads.h"

Go to the source code of this file.

Functions

static uint32_t Atomic_CompareAndSwap_u32 (uint32_t volatile *pDestination, uint32_t newValue, uint32_t comparand)
 Performs an atomic compare-and-swap operation on the given values. More...
 
static void * Atomic_Swap_Pointer (void *volatile *pDestination, void *pNewValue)
 Atomically writes a pointer value to memory. More...
 
static uint32_t Atomic_CompareAndSwap_Pointer (void *volatile *pDestination, void *pNewValue, void *pComparand)
 Performs an atomic compare-and-swap operation on the given pointers. More...
 
static uint32_t Atomic_Add_u32 (uint32_t volatile *pAugend, uint32_t addend)
 Performs an atomic addition of the given values. More...
 
static uint32_t Atomic_Subtract_u32 (uint32_t volatile *pMinuend, uint32_t subtrahend)
 Performs an atomic subtraction of the given values. More...
 
static uint32_t Atomic_Increment_u32 (uint32_t volatile *pAugend)
 Atomically adds 1 to the given value. More...
 
static uint32_t Atomic_Decrement_u32 (uint32_t volatile *pMinuend)
 Atomically subtracts 1 from the given value. More...
 
static uint32_t Atomic_OR_u32 (uint32_t volatile *pOperand, uint32_t mask)
 Performs an atomic bitwise OR of the given values. More...
 
static uint32_t Atomic_XOR_u32 (uint32_t volatile *pOperand, uint32_t mask)
 Performs an atomic bitwise XOR of the given values. More...
 
static uint32_t Atomic_AND_u32 (uint32_t volatile *pOperand, uint32_t mask)
 Performs an atomic bitwise AND of the given values. More...
 
static uint32_t Atomic_NAND_u32 (uint32_t volatile *pOperand, uint32_t mask)
 Performs an atomic bitwise NAND of the given values. More...
 

Detailed Description

Generic implementation of atomic operations.

This implementation is less efficient than the specific atomic implementations, but should work on all platforms.

Function Documentation

◆ Atomic_CompareAndSwap_u32()

static uint32_t Atomic_CompareAndSwap_u32 ( uint32_t volatile *  pDestination,
uint32_t  newValue,
uint32_t  comparand 
)
inlinestatic

Performs an atomic compare-and-swap operation on the given values.

Parameters
[in,out]pDestinationPointer to memory location from where value is to be loaded and checked.
[in]newValueThis value will be written to memory if the comparand matches the value at pDestination.
[in]comparandThis value is compared to the value at pDestination.
Returns
1 if the newValue was written to pDestination; 0 otherwise.

◆ Atomic_Swap_Pointer()

static void* Atomic_Swap_Pointer ( void *volatile *  pDestination,
void *  pNewValue 
)
inlinestatic

Atomically writes a pointer value to memory.

Parameters
[in,out]pDestinationWhere pNewValue will be written.
[in]pNewValueThe value to write to pDestination.
Returns
The initial value at pDestination.

◆ Atomic_CompareAndSwap_Pointer()

static uint32_t Atomic_CompareAndSwap_Pointer ( void *volatile *  pDestination,
void *  pNewValue,
void *  pComparand 
)
inlinestatic

Performs an atomic compare-and-swap operation on the given pointers.

Parameters
[in,out]pDestinationPointer to the memory location to be loaded and checked.
[in]pNewValueThis value will be written to memory if the comparand matches the value at pDestination.
[in]pComparandThis value is compared to the value at pDestination.
Returns
1 if the newValue was written to pDestination; 0 otherwise.

◆ Atomic_Add_u32()

static uint32_t Atomic_Add_u32 ( uint32_t volatile *  pAugend,
uint32_t  addend 
)
inlinestatic

Performs an atomic addition of the given values.

Parameters
[in,out]pAugendPointer to the augend and where the sum is stored.
[in]addendValue to add to the augend.
Returns
The initial value at pAugend.

◆ Atomic_Subtract_u32()

static uint32_t Atomic_Subtract_u32 ( uint32_t volatile *  pMinuend,
uint32_t  subtrahend 
)
inlinestatic

Performs an atomic subtraction of the given values.

Parameters
[in,out]pMinuendPointer to the minuend and where the difference is stored.
[in]subtrahendValue to subtract from the minuend.
Returns
The initial value at pMinuend.

◆ Atomic_Increment_u32()

static uint32_t Atomic_Increment_u32 ( uint32_t volatile *  pAugend)
inlinestatic

Atomically adds 1 to the given value.

Parameters
[in,out]pAugendPointer to the augend and where the sum is stored.
Returns
The initial value at pAugend.

◆ Atomic_Decrement_u32()

static uint32_t Atomic_Decrement_u32 ( uint32_t volatile *  pMinuend)
inlinestatic

Atomically subtracts 1 from the given value.

Parameters
[in,out]pMinuendPointer to the minuend and where the difference is stored.
Returns
The initial value at pMinuend.

◆ Atomic_OR_u32()

static uint32_t Atomic_OR_u32 ( uint32_t volatile *  pOperand,
uint32_t  mask 
)
inlinestatic

Performs an atomic bitwise OR of the given values.

Parameters
[in,out]pOperandPointer to operand and where the result is stored.
[in]maskMask to OR with the operand.
Returns
The initial value at pOperand.

◆ Atomic_XOR_u32()

static uint32_t Atomic_XOR_u32 ( uint32_t volatile *  pOperand,
uint32_t  mask 
)
inlinestatic

Performs an atomic bitwise XOR of the given values.

Parameters
[in,out]pOperandPointer to operand and where the result is stored.
[in]maskMask to XOR with the operand.
Returns
The initial value at pOperand.

◆ Atomic_AND_u32()

static uint32_t Atomic_AND_u32 ( uint32_t volatile *  pOperand,
uint32_t  mask 
)
inlinestatic

Performs an atomic bitwise AND of the given values.

Parameters
[in,out]pOperandPointer to operand and where the result is stored.
[in]maskMask to AND with the operand.
Returns
The initial value at pOperand.

◆ Atomic_NAND_u32()

static uint32_t Atomic_NAND_u32 ( uint32_t volatile *  pOperand,
uint32_t  mask 
)
inlinestatic

Performs an atomic bitwise NAND of the given values.

Parameters
[in,out]pOperandPointer to operand and where the result is stored.
[in]maskMask to NAND with the operand.
Returns
The initial value at pOperand.