Skip to content

Atomic Operations

Functions

Name
void wolfSSL_Atomic_Int_Init(wolfSSL_Atomic_Int * c, int i)
Initializes atomic integer.
void wolfSSL_Atomic_Uint_Init(wolfSSL_Atomic_Uint * c, unsigned int i)
Initializes atomic unsigned integer.
int wolfSSL_Atomic_Int_FetchAdd(wolfSSL_Atomic_Int * c, int i)
Atomically adds to integer and returns old value.
int wolfSSL_Atomic_Int_FetchSub(wolfSSL_Atomic_Int * c, int i)
Atomically subtracts from integer and returns old value.
int wolfSSL_Atomic_Int_AddFetch(wolfSSL_Atomic_Int * c, int i)
Atomically adds to integer and returns new value.
int wolfSSL_Atomic_Int_SubFetch(wolfSSL_Atomic_Int * c, int i)
Atomically subtracts from integer and returns new value.
int wolfSSL_Atomic_Int_CompareExchange(wolfSSL_Atomic_Int * c, int * expected_i, int new_i)
Atomically compares and exchanges integer.
unsigned int wolfSSL_Atomic_Uint_FetchAdd(wolfSSL_Atomic_Uint * c, unsigned int i)
Atomically adds to unsigned integer and returns old value.
unsigned int wolfSSL_Atomic_Uint_FetchSub(wolfSSL_Atomic_Uint * c, unsigned int i)
Atomically subtracts from unsigned integer, returns old value.
unsigned int wolfSSL_Atomic_Uint_AddFetch(wolfSSL_Atomic_Uint * c, unsigned int i)
Atomically adds to unsigned integer, returns new value.
unsigned int wolfSSL_Atomic_Uint_SubFetch(wolfSSL_Atomic_Uint * c, unsigned int i)
Atomically subtracts from unsigned integer, returns new value.
int wolfSSL_Atomic_Uint_CompareExchange(wolfSSL_Atomic_Uint * c, unsigned int * expected_i, unsigned int new_i)
Atomically compares and exchanges unsigned integer.
int wolfSSL_Atomic_Ptr_CompareExchange(void c, void expected_ptr, void * new_ptr)
Atomically compares and exchanges pointer.

Functions Documentation

function wolfSSL_Atomic_Int_Init

void wolfSSL_Atomic_Int_Init(
    wolfSSL_Atomic_Int * c,
    int i
)

Initializes atomic integer.

Parameters:

  • c Atomic integer pointer
  • i Initial value

See: wolfSSL_Atomic_Int_FetchAdd

Return: none No returns

Example

wolfSSL_Atomic_Int counter;
wolfSSL_Atomic_Int_Init(&counter, 0);

function wolfSSL_Atomic_Uint_Init

void wolfSSL_Atomic_Uint_Init(
    wolfSSL_Atomic_Uint * c,
    unsigned int i
)

Initializes atomic unsigned integer.

Parameters:

  • c Atomic unsigned integer pointer
  • i Initial value

See: wolfSSL_Atomic_Uint_FetchAdd

Return: none No returns

Example

wolfSSL_Atomic_Uint counter;
wolfSSL_Atomic_Uint_Init(&counter, 0);

function wolfSSL_Atomic_Int_FetchAdd

int wolfSSL_Atomic_Int_FetchAdd(
    wolfSSL_Atomic_Int * c,
    int i
)

Atomically adds to integer and returns old value.

Parameters:

  • c Atomic integer pointer
  • i Value to add

See: wolfSSL_Atomic_Int_AddFetch

Return: Old value before addition

Example

wolfSSL_Atomic_Int counter;
int old = wolfSSL_Atomic_Int_FetchAdd(&counter, 1);

function wolfSSL_Atomic_Int_FetchSub

int wolfSSL_Atomic_Int_FetchSub(
    wolfSSL_Atomic_Int * c,
    int i
)

Atomically subtracts from integer and returns old value.

Parameters:

  • c Atomic integer pointer
  • i Value to subtract

See: wolfSSL_Atomic_Int_SubFetch

Return: Old value before subtraction

Example

wolfSSL_Atomic_Int counter;
int old = wolfSSL_Atomic_Int_FetchSub(&counter, 1);

function wolfSSL_Atomic_Int_AddFetch

int wolfSSL_Atomic_Int_AddFetch(
    wolfSSL_Atomic_Int * c,
    int i
)

Atomically adds to integer and returns new value.

Parameters:

  • c Atomic integer pointer
  • i Value to add

See: wolfSSL_Atomic_Int_FetchAdd

Return: New value after addition

Example

wolfSSL_Atomic_Int counter;
int new_val = wolfSSL_Atomic_Int_AddFetch(&counter, 1);

function wolfSSL_Atomic_Int_SubFetch

int wolfSSL_Atomic_Int_SubFetch(
    wolfSSL_Atomic_Int * c,
    int i
)

Atomically subtracts from integer and returns new value.

Parameters:

  • c Atomic integer pointer
  • i Value to subtract

See: wolfSSL_Atomic_Int_FetchSub

Return: New value after subtraction

Example

wolfSSL_Atomic_Int counter;
int new_val = wolfSSL_Atomic_Int_SubFetch(&counter, 1);

function wolfSSL_Atomic_Int_CompareExchange

int wolfSSL_Atomic_Int_CompareExchange(
    wolfSSL_Atomic_Int * c,
    int * expected_i,
    int new_i
)

Atomically compares and exchanges integer.

Parameters:

  • c Atomic integer pointer
  • expected_i Pointer to expected value
  • new_i New value to set

See: wolfSSL_Atomic_Int_FetchAdd

Return: 1 if exchange occurred, 0 otherwise

Example

wolfSSL_Atomic_Int counter;
int expected = 0;
int ret = wolfSSL_Atomic_Int_CompareExchange(&counter, &expected, 1);

function wolfSSL_Atomic_Uint_FetchAdd

unsigned int wolfSSL_Atomic_Uint_FetchAdd(
    wolfSSL_Atomic_Uint * c,
    unsigned int i
)

Atomically adds to unsigned integer and returns old value.

Parameters:

  • c Atomic unsigned integer pointer
  • i Value to add

See: wolfSSL_Atomic_Uint_AddFetch

Return: Old value before addition

Example

wolfSSL_Atomic_Uint counter;
unsigned int old = wolfSSL_Atomic_Uint_FetchAdd(&counter, 1);

function wolfSSL_Atomic_Uint_FetchSub

unsigned int wolfSSL_Atomic_Uint_FetchSub(
    wolfSSL_Atomic_Uint * c,
    unsigned int i
)

Atomically subtracts from unsigned integer, returns old value.

Parameters:

  • c Atomic unsigned integer pointer
  • i Value to subtract

See: wolfSSL_Atomic_Uint_SubFetch

Return: Old value before subtraction

Example

wolfSSL_Atomic_Uint counter;
unsigned int old = wolfSSL_Atomic_Uint_FetchSub(&counter, 1);

function wolfSSL_Atomic_Uint_AddFetch

unsigned int wolfSSL_Atomic_Uint_AddFetch(
    wolfSSL_Atomic_Uint * c,
    unsigned int i
)

Atomically adds to unsigned integer, returns new value.

Parameters:

  • c Atomic unsigned integer pointer
  • i Value to add

See: wolfSSL_Atomic_Uint_FetchAdd

Return: New value after addition

Example

wolfSSL_Atomic_Uint counter;
unsigned int new_val = wolfSSL_Atomic_Uint_AddFetch(&counter, 1);

function wolfSSL_Atomic_Uint_SubFetch

unsigned int wolfSSL_Atomic_Uint_SubFetch(
    wolfSSL_Atomic_Uint * c,
    unsigned int i
)

Atomically subtracts from unsigned integer, returns new value.

Parameters:

  • c Atomic unsigned integer pointer
  • i Value to subtract

See: wolfSSL_Atomic_Uint_FetchSub

Return: New value after subtraction

Example

wolfSSL_Atomic_Uint counter;
unsigned int new_val = wolfSSL_Atomic_Uint_SubFetch(&counter, 1);

function wolfSSL_Atomic_Uint_CompareExchange

int wolfSSL_Atomic_Uint_CompareExchange(
    wolfSSL_Atomic_Uint * c,
    unsigned int * expected_i,
    unsigned int new_i
)

Atomically compares and exchanges unsigned integer.

Parameters:

  • c Atomic unsigned integer pointer
  • expected_i Pointer to expected value
  • new_i New value to set

See: wolfSSL_Atomic_Uint_FetchAdd

Return: 1 if exchange occurred, 0 otherwise

Example

wolfSSL_Atomic_Uint counter;
unsigned int expected = 0;
int ret = wolfSSL_Atomic_Uint_CompareExchange(&counter, &expected, 1);

function wolfSSL_Atomic_Ptr_CompareExchange

int wolfSSL_Atomic_Ptr_CompareExchange(
    void ** c,
    void ** expected_ptr,
    void * new_ptr
)

Atomically compares and exchanges pointer.

Parameters:

  • c Pointer to pointer
  • expected_ptr Pointer to expected pointer value
  • new_ptr New pointer value

See: wolfSSL_Atomic_Int_CompareExchange

Return: 1 if exchange occurred, 0 otherwise

Example

void* ptr = NULL;
void* expected = NULL;
void* new_val = malloc(100);
int ret = wolfSSL_Atomic_Ptr_CompareExchange(&ptr, &expected, new_val);

Updated on 2026-11-17 at 01:15:29 +0000