modm API documentation
|
Atomic access to objects. More...
#include <modm/architecture/driver/atomic/container.hpp>
Public Member Functions | |
Container (const T &data=T ()) | |
void | set (T value) |
T | get () |
T | swap (T value) |
Write a new value to the wrapped object and return the old value. More... | |
T & | directAccess () |
Get direct access to the object. More... | |
Atomic access to objects.
The atomic container wraps objects and provides atomic access to them. This comes in handy when simple objects are accessed by an interrupt and the main program. The container provides secure access without much work in this case.
Example:
If the interrupt routine is not interruptible (this is the default for the ATmega, but not for the ATxmega!) no atomic access is needed then:
This will slightly faster because no lock needs to be created.
If the object is big or a lot of accessed one after another are done, consider dropping this class and create critical sections for the access by yourself with modm::atomic::Lock.
This can be a lot faster because the object don't need to be copied as it is the case here!
|
inline |
Get direct access to the object.
|
inline |
Write a new value to the wrapped object and return the old value.
This function is needed quite often when exchanging flags between interrupt routines and the main-loop.
The same behavior for boolean values is provide by modm::atomic::Flag()