|
Data Structures | |
| struct | atomic_object |
| Implementation-specific structure holding an atomic object. More... | |
Defines | |
| #define | atomic_inc(ptr) atomic_add(ptr, 1) |
| Increment the memory object at ptr atomically. | |
| #define | atomic_dec(ptr) atomic_sub(ptr, 1) |
| Decrement the memory object at ptr atomically. | |
Typedefs | |
| typedef struct atomic_object | atomic_t |
| An atomic object representing a value which is manipulated atomically. | |
| typedef uint8_t | atomic_value_t |
| A value held by an atomic object. | |
Functions | |
| static atomic_value_t | atomic_read (atomic_t *ptr) |
| Return the value of the atomic object at ptr. | |
| static void | atomic_write (atomic_t *ptr, atomic_value_t value) |
| Write value to the atomic object at ptr. | |
| static atomic_t | atomic_add (atomic_t *ptr, atomic_value_t value) |
| Atomically add value to the value stored at ptr. | |
| static atomic_t | atomic_sub (atomic_t *ptr, atomic_value_t value) |
| Atomically subtract value from the value stored at ptr. | |
Atomic operations allow you to do certain arithmetic read-modify-write operations atomically. The atomic operations guarantee that the memory object being modified will not be altered by any other code while the operation is being carried out.
Normally, when incrementing a variable stored in memory, the processor will have to load the current value from memory into a register, increment the value in the register and store the result back into memory. If for example an interrupt comes along while this happens, and the interrupt handler modifies the same variable, the result will usually be wrong since the value stored by the interrupt handler will be ignored. If the variable is incremented using an atomic operation, the read-modify-write operation will happen in its entirety either before or after the interrupt handler runs, thus avoiding this problem.
One common way to implement atomic operations is to disable interrupts around the operation. However, some architectures may have specialized instructions which allow interrupts to be enabled while the read-modify-write operation is being carried out. It is therefore recommended to use atomic operations instead of disabling interrupts "manually" wherever possible.
| #define atomic_dec | ( | ptr | ) | atomic_sub(ptr, 1) |
| #define atomic_inc | ( | ptr | ) | atomic_add(ptr, 1) |
| struct atomic_object atomic_t |
An atomic object representing a value which is manipulated atomically.
| typedef uint8_t atomic_value_t |
| atomic_t atomic_add | ( | atomic_t * | ptr, | |
| atomic_value_t | value | |||
| ) | [inline, static] |
Atomically add value to the value stored at ptr.
Definition at line 78 of file atomic.h.
References cpu_irq_restore(), cpu_irq_save(), and atomic_object::value.
| atomic_value_t atomic_read | ( | atomic_t * | ptr | ) | [inline, static] |
Return the value of the atomic object at ptr.
Definition at line 66 of file atomic.h.
References barrier, and atomic_object::value.
| atomic_t atomic_sub | ( | atomic_t * | ptr, | |
| atomic_value_t | value | |||
| ) | [inline, static] |
Atomically subtract value from the value stored at ptr.
Definition at line 91 of file atomic.h.
References cpu_irq_restore(), cpu_irq_save(), and atomic_object::value.
| void atomic_write | ( | atomic_t * | ptr, | |
| atomic_value_t | value | |||
| ) | [inline, static] |
Write value to the atomic object at ptr.
Definition at line 72 of file atomic.h.
References barrier, and atomic_object::value.
1.6.3