GATE
Loading...
Searching...
No Matches
atomics.h File Reference

Atomic integer and pointer operations. More...

#include "gate/gate_core_api.h"
#include "gate/gatetypes.h"

Data Structures

struct  gate_atomic_flag_class
 atomic flag storage type More...
 
struct  gate_atomic_lock_class
 atomic lock storage (generic, non-recursive) type More...
 
struct  gate_atomic_rlock_t
 atomic recursive lock storage type More...
 

Macros

#define GATE_ATOMIC_FLAG_INIT   { 0 }
 initialization value for gate_atomic_flag_t variables
 
#define GATE_ATOMIC_LOCK_INIT   { 0 }
 initialization value for gate_atomic_lock_t variables
 
#define GATE_ATOMIC_RLOCK_INIT   { 0 }
 initialization value for gate_atomic_lock_t variables
 

Typedefs

typedef struct gate_atomic_flag_class gate_atomic_flag_t
 atomic flag storage type
 
typedef gate_int32_t volatile gate_atomic_int_t
 atomic integer storage type
 
typedef gate_int64_t volatile gate_atomic_int64_t
 atomic 64-bit integer storage type
 
typedef void *volatile gate_atomic_ptr_t
 atomic pointer storage type
 
typedef struct gate_atomic_lock_class gate_atomic_lock_t
 atomic lock storage (generic, non-recursive) type
 

Functions

GATE_CORE_API gate_bool_t gate_atomic_flag_set (gate_atomic_flag_t *atom)
 Sets an atomic flag to true and returns it previous state.
 
GATE_CORE_API void gate_atomic_flag_clear (gate_atomic_flag_t *atom)
 Sets an atomic flag to false.
 
GATE_CORE_API void gate_atomic_int_init (gate_atomic_int_t *atom, gate_int32_t value)
 Initializes an uninitialized atomic integer with a specific numeric value.
 
GATE_CORE_API gate_int32_t gate_atomic_int_set (gate_atomic_int_t *atom, gate_int32_t value)
 Sets an atomic integer to a new value and returns its previous value.
 
GATE_CORE_API gate_int32_t gate_atomic_int_get (gate_atomic_int_t *atom)
 Returns the current atomic integer value.
 
GATE_CORE_API gate_int32_t gate_atomic_int_inc (gate_atomic_int_t *atom)
 Increments an atomic integer value by 1.
 
GATE_CORE_API gate_int32_t gate_atomic_int_dec (gate_atomic_int_t *atom)
 Decrements an atomic integer value by 1.
 
GATE_CORE_API gate_int32_t gate_atomic_int_add (gate_atomic_int_t *atom, gate_int32_t value)
 Adds a value to an atomic integer.
 
GATE_CORE_API gate_int32_t gate_atomic_int_xchg_if (gate_atomic_int_t *atom, gate_int32_t comparand, gate_int32_t xchgvalue)
 Set an atomic integer to a new value, if the current value equals a specific value.
 
GATE_CORE_API gate_bool_t gate_atomic_int_update_if (gate_atomic_int_t *atom, gate_int32_t fromvalue, gate_int32_t tovalue)
 Updates an atomic integer to a new value, if the current value equals a specific value.
 
GATE_CORE_API void gate_atomic_int64_init (gate_atomic_int64_t *atom, gate_int64_t value)
 Initializes an uninitialized atomic 64bit integer with a specific numeric value.
 
GATE_CORE_API gate_int64_t gate_atomic_int64_set (gate_atomic_int64_t *atom, gate_int64_t value)
 Sets an atomic 64bit integer to a new value and returns its previous value.
 
GATE_CORE_API gate_int64_t gate_atomic_int64_get (gate_atomic_int64_t *atom)
 Returns the current atomic 64bit integer value.
 
GATE_CORE_API gate_int64_t gate_atomic_int64_inc (gate_atomic_int64_t *atom)
 Increments an atomic 64bit integer value by 1.
 
GATE_CORE_API gate_int64_t gate_atomic_int64_dec (gate_atomic_int64_t *atom)
 Decrements an atomic 64bit integer value by 1.
 
GATE_CORE_API gate_int64_t gate_atomic_int64_add (gate_atomic_int64_t *atom, gate_int64_t value)
 Adds a value to an atomic 64bit integer.
 
GATE_CORE_API gate_int64_t gate_atomic_int64_xchg_if (gate_atomic_int64_t *atom, gate_int64_t comparand, gate_int64_t xchgvalue)
 Set an atomic 64bit integer to a new value, if the current value equals a specific value.
 
GATE_CORE_API void gate_atomic_ptr_init (gate_atomic_ptr_t *atom, void *value)
 Initializes an uninitialized atomic pointer with a specific address.
 
GATE_CORE_API void * gate_atomic_ptr_set (gate_atomic_ptr_t *atom, void *value)
 Sets an atomic pointer to a new address and returns its previous address.
 
GATE_CORE_API void * gate_atomic_ptr_get (gate_atomic_ptr_t *atom)
 Returns the current atomic pointer address.
 
GATE_CORE_API void * gate_atomic_ptr_xchg_if (gate_atomic_ptr_t *atom, void *comparand, void *xchgvalue)
 Set an atomic pointer to a new address, if the current address equals a specific address.
 
GATE_CORE_API void gate_atomic_lock_acquire (gate_atomic_lock_t *atom)
 Aquires an atomic lock by spinning until it is available.
 
GATE_CORE_API gate_bool_t gate_atomic_lock_acquire_spin (gate_atomic_lock_t *atom, gate_uint32_t spincount)
 Tries to acquire an atomic lock within a spin-limit.
 
GATE_CORE_API void gate_atomic_lock_release (gate_atomic_lock_t *atom)
 Releases an owned atomic lock.
 
GATE_CORE_API void gate_atomic_rlock_acquire (gate_atomic_rlock_t *atom)
 Aquires an atomic recursive lock by spinning until it is available.
 
GATE_CORE_API gate_bool_t gate_atomic_rlock_acquire_spin (gate_atomic_rlock_t *atom, gate_uint32_t spincount)
 Tries to acquire an atomic recursive lock within a spin-limit.
 
GATE_CORE_API void gate_atomic_rlock_release (gate_atomic_rlock_t *atom)
 Releases an owned atomic recursive lock.
 
GATE_CORE_API void gate_atomic_call_once (gate_atomic_flag_t *ptr_once_flag, void(*func)(void))
 Runs a given function only the first time it is invoked.
 
GATE_CORE_API void gate_atomic_call_once_exclusive (gate_atomic_flag_t *ptr_once_flag, void(*func)(void))
 Runs a given function only the first time it is invoked and exclusively locks the function call.
 

Detailed Description

Atomic integer and pointer operations.

Function Documentation

◆ gate_atomic_flag_set()

GATE_CORE_API gate_bool_t gate_atomic_flag_set ( gate_atomic_flag_t * atom)

Sets an atomic flag to true and returns it previous state.

Parameters
[in,out]atomPointer to atomic flag stoarge
Returns
previous value of atomic flag before update

◆ gate_atomic_flag_clear()

GATE_CORE_API void gate_atomic_flag_clear ( gate_atomic_flag_t * atom)

Sets an atomic flag to false.

Parameters
[in,out]atomPointer to atomic flag stoarge

◆ gate_atomic_int_init()

GATE_CORE_API void gate_atomic_int_init ( gate_atomic_int_t * atom,
gate_int32_t value )

Initializes an uninitialized atomic integer with a specific numeric value.

Parameters
[out]atomPointer to atomic integer storage
[in]valuenew value of atomic integer

◆ gate_atomic_int_set()

GATE_CORE_API gate_int32_t gate_atomic_int_set ( gate_atomic_int_t * atom,
gate_int32_t value )

Sets an atomic integer to a new value and returns its previous value.

Parameters
[in,out]atomPointer to atomic integer storage
[in]valueNew value of atomic integer
Returns
Previous value of atomic integer before update

◆ gate_atomic_int_get()

GATE_CORE_API gate_int32_t gate_atomic_int_get ( gate_atomic_int_t * atom)

Returns the current atomic integer value.

Parameters
[in,out]atomPointer to atomic integer storage
Returns
Current value of atomic integer

◆ gate_atomic_int_inc()

GATE_CORE_API gate_int32_t gate_atomic_int_inc ( gate_atomic_int_t * atom)

Increments an atomic integer value by 1.

Parameters
[in,out]atomPointer to atomic integer storage
Returns
Final value of atomic integer after incrementation

◆ gate_atomic_int_dec()

GATE_CORE_API gate_int32_t gate_atomic_int_dec ( gate_atomic_int_t * atom)

Decrements an atomic integer value by 1.

Parameters
[in,out]atomPointer to atomic integer storage
Returns
Final value of atomic integer after decrementation

◆ gate_atomic_int_add()

GATE_CORE_API gate_int32_t gate_atomic_int_add ( gate_atomic_int_t * atom,
gate_int32_t value )

Adds a value to an atomic integer.

Parameters
[in,out]atomPointer to atomic integer storage
[in]valueValue to be added (or subtracted if negative)
Returns
Final value of atomic integer after addition

◆ gate_atomic_int_xchg_if()

GATE_CORE_API gate_int32_t gate_atomic_int_xchg_if ( gate_atomic_int_t * atom,
gate_int32_t comparand,
gate_int32_t xchgvalue )

Set an atomic integer to a new value, if the current value equals a specific value.

Parameters
[in,out]atomPointer to atomic integer storage
[in]comparandValue to be compared to atomic integer, if unequal no update is applied
[in]xchgvalueValue to be applied, if 'comparand' equals the current value
Returns
Previous value of atomic integer (before update)

◆ gate_atomic_int_update_if()

GATE_CORE_API gate_bool_t gate_atomic_int_update_if ( gate_atomic_int_t * atom,
gate_int32_t fromvalue,
gate_int32_t tovalue )

Updates an atomic integer to a new value, if the current value equals a specific value.

Parameters
[in,out]atomPointer to atomic integer storage
[in]fromvalueValue to be compared to atomic integer, if unequal no update is applied
[in]tovalueValue to be applied, if 'comparand' equals the current value
Returns
true in case the update was applied, false if no update was applied.

◆ gate_atomic_int64_init()

GATE_CORE_API void gate_atomic_int64_init ( gate_atomic_int64_t * atom,
gate_int64_t value )

Initializes an uninitialized atomic 64bit integer with a specific numeric value.

Parameters
[out]atomPointer to atomic 64bit integer storage
[in]valuenew value of atomic 64bit integer

◆ gate_atomic_int64_set()

GATE_CORE_API gate_int64_t gate_atomic_int64_set ( gate_atomic_int64_t * atom,
gate_int64_t value )

Sets an atomic 64bit integer to a new value and returns its previous value.

Parameters
[in,out]atomPointer to atomic 64bit integer storage
[in]valuenew value of atomic 64bit integer
Returns
previous value of atomic 64bit integer before update

◆ gate_atomic_int64_get()

GATE_CORE_API gate_int64_t gate_atomic_int64_get ( gate_atomic_int64_t * atom)

Returns the current atomic 64bit integer value.

Parameters
[in,out]atomPointer to atomic 64bit integer storage
Returns
current value of atomic 64bit integer

◆ gate_atomic_int64_inc()

GATE_CORE_API gate_int64_t gate_atomic_int64_inc ( gate_atomic_int64_t * atom)

Increments an atomic 64bit integer value by 1.

Parameters
[in,out]atomPointer to atomic 64bit integer storage
Returns
final value of atomic 64bit integer after incrementation

◆ gate_atomic_int64_dec()

GATE_CORE_API gate_int64_t gate_atomic_int64_dec ( gate_atomic_int64_t * atom)

Decrements an atomic 64bit integer value by 1.

Parameters
[in,out]atomPointer to atomic 64bit integer storage
Returns
final value of atomic 64bit integer after decrementation

◆ gate_atomic_int64_add()

GATE_CORE_API gate_int64_t gate_atomic_int64_add ( gate_atomic_int64_t * atom,
gate_int64_t value )

Adds a value to an atomic 64bit integer.

Parameters
[in,out]atomPointer to atomic 64bit integer storage
[in]valueValue to be added (or subtracted if negative)
Returns
final value of atomic 64bit integer after addition

◆ gate_atomic_int64_xchg_if()

GATE_CORE_API gate_int64_t gate_atomic_int64_xchg_if ( gate_atomic_int64_t * atom,
gate_int64_t comparand,
gate_int64_t xchgvalue )

Set an atomic 64bit integer to a new value, if the current value equals a specific value.

Parameters
[in,out]atomPointer to atomic 64bit integer storage
[in]comparandValue to be compared to atomic 64bit integer, if unequal no update is applied
[in]xchgvalueValue to be applied, if 'comparand' equals the current value
Returns
Previous value of atomic 64bit integer (before update)

◆ gate_atomic_ptr_init()

GATE_CORE_API void gate_atomic_ptr_init ( gate_atomic_ptr_t * atom,
void * value )

Initializes an uninitialized atomic pointer with a specific address.

Parameters
[out]atomPointer to atomic pointer storage
[in]valuenew address of atomic pointer

◆ gate_atomic_ptr_set()

GATE_CORE_API void * gate_atomic_ptr_set ( gate_atomic_ptr_t * atom,
void * value )

Sets an atomic pointer to a new address and returns its previous address.

Parameters
[in,out]atomPointer to atomic pointer storage
[in]valuenew address of atomic pointer
Returns
previous address of atomic pointer before update

◆ gate_atomic_ptr_get()

GATE_CORE_API void * gate_atomic_ptr_get ( gate_atomic_ptr_t * atom)

Returns the current atomic pointer address.

Parameters
[in,out]atomPointer to atomic pointer storage
Returns
Current address of atomic pointer

◆ gate_atomic_ptr_xchg_if()

GATE_CORE_API void * gate_atomic_ptr_xchg_if ( gate_atomic_ptr_t * atom,
void * comparand,
void * xchgvalue )

Set an atomic pointer to a new address, if the current address equals a specific address.

Parameters
[in,out]atomPointer to atomic pointer storage
[in]comparandAddress to be compared to atomic pointer, if unequal no update is applied
[in]xchgvalueAddress to be applied, if 'comparand' equals the current address
Returns
Previous address of atomic pointer (before update)

◆ gate_atomic_lock_acquire()

GATE_CORE_API void gate_atomic_lock_acquire ( gate_atomic_lock_t * atom)

Aquires an atomic lock by spinning until it is available.

Parameters
[in,out]atomPointer to atomic lock storage

◆ gate_atomic_lock_acquire_spin()

GATE_CORE_API gate_bool_t gate_atomic_lock_acquire_spin ( gate_atomic_lock_t * atom,
gate_uint32_t spincount )

Tries to acquire an atomic lock within a spin-limit.

Parameters
[in,out]atomPointer to atomic lock storage
[in]spincountCount of lock aquire attempts
Returns
'true', if lock was aquired, or 'false' if lock is unavailable within spin-count

◆ gate_atomic_lock_release()

GATE_CORE_API void gate_atomic_lock_release ( gate_atomic_lock_t * atom)

Releases an owned atomic lock.

Parameters
[in,out]atomPointer to atomic lock storage

◆ gate_atomic_rlock_acquire()

GATE_CORE_API void gate_atomic_rlock_acquire ( gate_atomic_rlock_t * atom)

Aquires an atomic recursive lock by spinning until it is available.

Parameters
[in,out]atomPointer to atomic recursive lock storage

◆ gate_atomic_rlock_acquire_spin()

GATE_CORE_API gate_bool_t gate_atomic_rlock_acquire_spin ( gate_atomic_rlock_t * atom,
gate_uint32_t spincount )

Tries to acquire an atomic recursive lock within a spin-limit.

Parameters
[in,out]atomPointer to atomic recursive lock storage
[in]spincountMaximum count of lock aquire attempts
Returns
'true', if lock was aquired, or 'false' if lock is unavailable within spin-count

◆ gate_atomic_rlock_release()

GATE_CORE_API void gate_atomic_rlock_release ( gate_atomic_rlock_t * atom)

Releases an owned atomic recursive lock.

Parameters
[in,out]atomPointer to atomic recursive lock storage

◆ gate_atomic_call_once()

GATE_CORE_API void gate_atomic_call_once ( gate_atomic_flag_t * ptr_once_flag,
void(* func )(void) )

Runs a given function only the first time it is invoked.

Parameters
[in,out]ptr_once_flagPointer to flag variable that stores the state
[in]funcFunction to be called

◆ gate_atomic_call_once_exclusive()

GATE_CORE_API void gate_atomic_call_once_exclusive ( gate_atomic_flag_t * ptr_once_flag,
void(* func )(void) )

Runs a given function only the first time it is invoked and exclusively locks the function call.

Parameters
[in,out]ptr_once_flagPointer to flag variable that stores the state
[in]funcFunction to be called