Zephyr API Documentation  2.7.0-rc2
A Scalable Open Source RTOS
Atomic Services APIs

Macros

#define ATOMIC_INIT(i)   (i)
 Initialize an atomic variable. More...
 
#define ATOMIC_PTR_INIT(p)   (p)
 Initialize an atomic pointer variable. More...
 
#define ATOMIC_BITMAP_SIZE(num_bits)   (1 + ((num_bits) - 1) / ATOMIC_BITS)
 This macro computes the number of atomic variables necessary to represent a bitmap with num_bits. More...
 
#define ATOMIC_DEFINE(name, num_bits)    atomic_t name[ATOMIC_BITMAP_SIZE(num_bits)]
 Define an array of atomic variables. More...
 

Functions

static bool atomic_test_bit (const atomic_t *target, int bit)
 Atomically test a bit. More...
 
static bool atomic_test_and_clear_bit (atomic_t *target, int bit)
 Atomically test and clear a bit. More...
 
static bool atomic_test_and_set_bit (atomic_t *target, int bit)
 Atomically set a bit. More...
 
static void atomic_clear_bit (atomic_t *target, int bit)
 Atomically clear a bit. More...
 
static void atomic_set_bit (atomic_t *target, int bit)
 Atomically set a bit. More...
 
static void atomic_set_bit_to (atomic_t *target, int bit, bool val)
 Atomically set a bit to a given value. More...
 
static bool atomic_cas (atomic_t *target, atomic_val_t old_value, atomic_val_t new_value)
 Atomic compare-and-set. More...
 
static bool atomic_ptr_cas (atomic_ptr_t *target, atomic_ptr_val_t old_value, atomic_ptr_val_t new_value)
 Atomic compare-and-set with pointer values. More...
 
static atomic_val_t atomic_add (atomic_t *target, atomic_val_t value)
 Atomic addition. More...
 
static atomic_val_t atomic_sub (atomic_t *target, atomic_val_t value)
 Atomic subtraction. More...
 
static atomic_val_t atomic_inc (atomic_t *target)
 Atomic increment. More...
 
static atomic_val_t atomic_dec (atomic_t *target)
 Atomic decrement. More...
 
static atomic_val_t atomic_get (const atomic_t *target)
 Atomic get. More...
 
static atomic_ptr_val_t atomic_ptr_get (const atomic_ptr_t *target)
 Atomic get a pointer value. More...
 
static atomic_val_t atomic_set (atomic_t *target, atomic_val_t value)
 Atomic get-and-set. More...
 
static atomic_ptr_val_t atomic_ptr_set (atomic_ptr_t *target, atomic_ptr_val_t value)
 Atomic get-and-set for pointer values. More...
 
static atomic_val_t atomic_clear (atomic_t *target)
 Atomic clear. More...
 
static atomic_ptr_val_t atomic_ptr_clear (atomic_ptr_t *target)
 Atomic clear of a pointer value. More...
 
static atomic_val_t atomic_or (atomic_t *target, atomic_val_t value)
 Atomic bitwise inclusive OR. More...
 
static atomic_val_t atomic_xor (atomic_t *target, atomic_val_t value)
 Atomic bitwise exclusive OR (XOR). More...
 
static atomic_val_t atomic_and (atomic_t *target, atomic_val_t value)
 Atomic bitwise AND. More...
 
static atomic_val_t atomic_nand (atomic_t *target, atomic_val_t value)
 Atomic bitwise NAND. More...
 

Detailed Description

Macro Definition Documentation

◆ ATOMIC_BITMAP_SIZE

#define ATOMIC_BITMAP_SIZE (   num_bits)    (1 + ((num_bits) - 1) / ATOMIC_BITS)

#include <include/sys/atomic.h>

This macro computes the number of atomic variables necessary to represent a bitmap with num_bits.

Parameters
num_bitsNumber of bits.

◆ ATOMIC_DEFINE

#define ATOMIC_DEFINE (   name,
  num_bits 
)     atomic_t name[ATOMIC_BITMAP_SIZE(num_bits)]

#include <include/sys/atomic.h>

Define an array of atomic variables.

This macro defines an array of atomic variables containing at least num_bits bits.

Note
If used from file scope, the bits of the array are initialized to zero; if used from within a function, the bits are left uninitialized.
Parameters
nameName of array of atomic variables.
num_bitsNumber of bits needed.

◆ ATOMIC_INIT

#define ATOMIC_INIT (   i)    (i)

#include <include/sys/atomic.h>

Initialize an atomic variable.

This macro can be used to initialize an atomic variable. For example,

atomic_t my_var = ATOMIC_INIT(75);
int atomic_t
Definition: atomic.h:21
#define ATOMIC_INIT(i)
Initialize an atomic variable.
Definition: atomic.h:61
Parameters
iValue to assign to atomic variable.

◆ ATOMIC_PTR_INIT

#define ATOMIC_PTR_INIT (   p)    (p)

#include <include/sys/atomic.h>

Initialize an atomic pointer variable.

This macro can be used to initialize an atomic pointer variable. For example,

void * atomic_ptr_t
Definition: atomic.h:23
#define ATOMIC_PTR_INIT(p)
Initialize an atomic pointer variable.
Definition: atomic.h:72
static fdata_t data[2]
Definition: test_fifo_contexts.c:15
Parameters
pPointer value to assign to atomic pointer variable.

Function Documentation

◆ atomic_add()

static atomic_val_t atomic_add ( atomic_t target,
atomic_val_t  value 
)
inlinestatic

#include <include/sys/atomic_builtin.h>

Atomic addition.

This routine performs an atomic addition on target.

Parameters
targetAddress of atomic variable.
valueValue to add.
Returns
Previous value of target.

◆ atomic_and()

static atomic_val_t atomic_and ( atomic_t target,
atomic_val_t  value 
)
inlinestatic

#include <include/sys/atomic_builtin.h>

Atomic bitwise AND.

This routine atomically sets target to the bitwise AND of target and value.

Parameters
targetAddress of atomic variable.
valueValue to AND.
Returns
Previous value of target.

◆ atomic_cas()

static bool atomic_cas ( atomic_t target,
atomic_val_t  old_value,
atomic_val_t  new_value 
)
inlinestatic

#include <include/sys/atomic_builtin.h>

Atomic compare-and-set.

This routine performs an atomic compare-and-set on target. If the current value of target equals old_value, target is set to new_value. If the current value of target does not equal old_value, target is left unchanged.

Parameters
targetAddress of atomic variable.
old_valueOriginal value to compare against.
new_valueNew value to store.
Returns
true if new_value is written, false otherwise.

◆ atomic_clear()

static atomic_val_t atomic_clear ( atomic_t target)
inlinestatic

#include <include/sys/atomic_builtin.h>

Atomic clear.

This routine atomically sets target to zero and returns its previous value. (Hence, it is equivalent to atomic_set(target, 0).)

Parameters
targetAddress of atomic variable.
Returns
Previous value of target.

◆ atomic_clear_bit()

static void atomic_clear_bit ( atomic_t target,
int  bit 
)
inlinestatic

#include <include/sys/atomic.h>

Atomically clear a bit.

Atomically clear bit number bit of target. The target may be a single atomic variable or an array of them.

Parameters
targetAddress of atomic variable or array.
bitBit number (starting from 0).
Returns
N/A

◆ atomic_dec()

static atomic_val_t atomic_dec ( atomic_t target)
inlinestatic

#include <include/sys/atomic_builtin.h>

Atomic decrement.

This routine performs an atomic decrement by 1 on target.

Parameters
targetAddress of atomic variable.
Returns
Previous value of target.

◆ atomic_get()

static atomic_val_t atomic_get ( const atomic_t target)
inlinestatic

#include <include/sys/atomic_builtin.h>

Atomic get.

This routine performs an atomic read on target.

Parameters
targetAddress of atomic variable.
Returns
Value of target.

◆ atomic_inc()

static atomic_val_t atomic_inc ( atomic_t target)
inlinestatic

#include <include/sys/atomic_builtin.h>

Atomic increment.

This routine performs an atomic increment by 1 on target.

Parameters
targetAddress of atomic variable.
Returns
Previous value of target.

◆ atomic_nand()

static atomic_val_t atomic_nand ( atomic_t target,
atomic_val_t  value 
)
inlinestatic

#include <include/sys/atomic_builtin.h>

Atomic bitwise NAND.

This routine atomically sets target to the bitwise NAND of target and value. (This operation is equivalent to target = ~(target & value).)

Parameters
targetAddress of atomic variable.
valueValue to NAND.
Returns
Previous value of target.

◆ atomic_or()

static atomic_val_t atomic_or ( atomic_t target,
atomic_val_t  value 
)
inlinestatic

#include <include/sys/atomic_builtin.h>

Atomic bitwise inclusive OR.

This routine atomically sets target to the bitwise inclusive OR of target and value.

Parameters
targetAddress of atomic variable.
valueValue to OR.
Returns
Previous value of target.

◆ atomic_ptr_cas()

static bool atomic_ptr_cas ( atomic_ptr_t target,
atomic_ptr_val_t  old_value,
atomic_ptr_val_t  new_value 
)
inlinestatic

#include <include/sys/atomic_builtin.h>

Atomic compare-and-set with pointer values.

This routine performs an atomic compare-and-set on target. If the current value of target equals old_value, target is set to new_value. If the current value of target does not equal old_value, target is left unchanged.

Parameters
targetAddress of atomic variable.
old_valueOriginal value to compare against.
new_valueNew value to store.
Returns
true if new_value is written, false otherwise.

◆ atomic_ptr_clear()

static atomic_ptr_val_t atomic_ptr_clear ( atomic_ptr_t target)
inlinestatic

#include <include/sys/atomic_builtin.h>

Atomic clear of a pointer value.

This routine atomically sets target to zero and returns its previous value. (Hence, it is equivalent to atomic_set(target, 0).)

Parameters
targetAddress of atomic variable.
Returns
Previous value of target.

◆ atomic_ptr_get()

static atomic_ptr_val_t atomic_ptr_get ( const atomic_ptr_t target)
inlinestatic

#include <include/sys/atomic_builtin.h>

Atomic get a pointer value.

This routine performs an atomic read on target.

Parameters
targetAddress of pointer variable.
Returns
Value of target.

◆ atomic_ptr_set()

static atomic_ptr_val_t atomic_ptr_set ( atomic_ptr_t target,
atomic_ptr_val_t  value 
)
inlinestatic

#include <include/sys/atomic_builtin.h>

Atomic get-and-set for pointer values.

This routine atomically sets target to value and returns the previous value of target.

Parameters
targetAddress of atomic variable.
valueValue to write to target.
Returns
Previous value of target.

◆ atomic_set()

static atomic_val_t atomic_set ( atomic_t target,
atomic_val_t  value 
)
inlinestatic

#include <include/sys/atomic_builtin.h>

Atomic get-and-set.

This routine atomically sets target to value and returns the previous value of target.

Parameters
targetAddress of atomic variable.
valueValue to write to target.
Returns
Previous value of target.

◆ atomic_set_bit()

static void atomic_set_bit ( atomic_t target,
int  bit 
)
inlinestatic

#include <include/sys/atomic.h>

Atomically set a bit.

Atomically set bit number bit of target. The target may be a single atomic variable or an array of them.

Parameters
targetAddress of atomic variable or array.
bitBit number (starting from 0).
Returns
N/A

◆ atomic_set_bit_to()

static void atomic_set_bit_to ( atomic_t target,
int  bit,
bool  val 
)
inlinestatic

#include <include/sys/atomic.h>

Atomically set a bit to a given value.

Atomically set bit number bit of target to value val. The target may be a single atomic variable or an array of them.

Parameters
targetAddress of atomic variable or array.
bitBit number (starting from 0).
valtrue for 1, false for 0.
Returns
N/A

◆ atomic_sub()

static atomic_val_t atomic_sub ( atomic_t target,
atomic_val_t  value 
)
inlinestatic

#include <include/sys/atomic_builtin.h>

Atomic subtraction.

This routine performs an atomic subtraction on target.

Parameters
targetAddress of atomic variable.
valueValue to subtract.
Returns
Previous value of target.

◆ atomic_test_and_clear_bit()

static bool atomic_test_and_clear_bit ( atomic_t target,
int  bit 
)
inlinestatic

#include <include/sys/atomic.h>

Atomically test and clear a bit.

Atomically clear bit number bit of target and return its old value. The target may be a single atomic variable or an array of them.

Parameters
targetAddress of atomic variable or array.
bitBit number (starting from 0).
Returns
true if the bit was set, false if it wasn't.

◆ atomic_test_and_set_bit()

static bool atomic_test_and_set_bit ( atomic_t target,
int  bit 
)
inlinestatic

#include <include/sys/atomic.h>

Atomically set a bit.

Atomically set bit number bit of target and return its old value. The target may be a single atomic variable or an array of them.

Parameters
targetAddress of atomic variable or array.
bitBit number (starting from 0).
Returns
true if the bit was set, false if it wasn't.

◆ atomic_test_bit()

static bool atomic_test_bit ( const atomic_t target,
int  bit 
)
inlinestatic

#include <include/sys/atomic.h>

Atomically test a bit.

This routine tests whether bit number bit of target is set or not. The target may be a single atomic variable or an array of them.

Parameters
targetAddress of atomic variable or array.
bitBit number (starting from 0).
Returns
true if the bit was set, false if it wasn't.

◆ atomic_xor()

static atomic_val_t atomic_xor ( atomic_t target,
atomic_val_t  value 
)
inlinestatic

#include <include/sys/atomic_builtin.h>

Atomic bitwise exclusive OR (XOR).

This routine atomically sets target to the bitwise exclusive OR (XOR) of target and value.

Parameters
targetAddress of atomic variable.
valueValue to XOR
Returns
Previous value of target.