pico]OS  1.0.4
Functions
Atomic Variables
User API: Pico Layer

Functions

POSEXTERN void POSCALL posAtomicSet (POSATOMIC_t *var, INT_t value)
POSEXTERN INT_t POSCALL posAtomicGet (POSATOMIC_t *var)
POSEXTERN INT_t POSCALL posAtomicAdd (POSATOMIC_t *var, INT_t value)
POSEXTERN INT_t POSCALL posAtomicSub (POSATOMIC_t *var, INT_t value)

Detailed Description

Atomic variables are variables that can be accessed in an atomic manner, that means a read-modify-write instruction is done in virtually one single cycle. For example, the atomic access to a variable is necessary when two tasks will do read-modify-write operations on a common variable. Under usual circumstances you can ran into trouble when a task that is just modifying the variable (that means it has read and modified the variable but has not yet written the result back) is interrupted by a second task that also modifies the variable. Thus the modification the first task has done would be lost. Atomic variables prevent this possible race condition.

pico]OS supports four functions to operate on atomic variables: posAtomicSet, posAtomicGet, posAtomicAdd and posAtomicSub.


Function Documentation

POSEXTERN INT_t POSCALL posAtomicAdd ( POSATOMIC_t var,
INT_t  value 
)

Atomic Variable Function. Adds a value onto the current value of the atomic variable.

Parameters:
varpointer to the atomic variable.
valuevalue that shall be added to the atomic variable.
Returns:
the content of the atomic variable before it was incremented.
Note:
POSCFG_FEATURE_ATOMICVAR must be defined to 1 to have atomic variable support compiled in.
See also:
posAtomicSet, posAtomicGet, posAtomicSub
POSEXTERN INT_t POSCALL posAtomicGet ( POSATOMIC_t var)

Atomic Variable Function. Returns the current value of an atomic variable.

Parameters:
varpointer to the atomic variable which value shall be read and returned.
Returns:
the value of the atomic variable.
Note:
POSCFG_FEATURE_ATOMICVAR must be defined to 1 to have atomic variable support compiled in.
See also:
posAtomicSet, posAtomicAdd, posAtomicSub
POSEXTERN void POSCALL posAtomicSet ( POSATOMIC_t var,
INT_t  value 
)

Atomic Variable Function. Sets an atomic variable to the specified value.

Parameters:
varpointer to the atomic variable that shall be set.
valuethe value the atomic variable shall be set to.
Note:
POSCFG_FEATURE_ATOMICVAR must be defined to 1 to have atomic variable support compiled in.
See also:
posAtomicGet, posAtomicAdd, posAtomicSub
POSEXTERN INT_t POSCALL posAtomicSub ( POSATOMIC_t var,
INT_t  value 
)

Atomic Variable Function. Substracts a value from the current value of the atomic variable.

Parameters:
varpointer to the atomic variable.
valuevalue that shall be substracted from the atomic variable.
Returns:
the content of the atomic variable before it was decremented.
Note:
POSCFG_FEATURE_ATOMICVAR must be defined to 1 to have atomic variable support compiled in.
See also:
posAtomicSet, posAtomicGet, posAtomicAdd