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
Atomic Variable Function. Adds a value onto the current value of the atomic variable.
- Parameters:
-
var | pointer to the atomic variable. |
value | value 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
Atomic Variable Function. Returns the current value of an atomic variable.
- Parameters:
-
var | pointer 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
Atomic Variable Function. Sets an atomic variable to the specified value.
- Parameters:
-
var | pointer to the atomic variable that shall be set. |
value | the 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
Atomic Variable Function. Substracts a value from the current value of the atomic variable.
- Parameters:
-
var | pointer to the atomic variable. |
value | value 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