|
oveRTOS C++ API
C++20 RAII wrappers for the oveRTOS C API
|
Thread-safe, lazily initialised storage cell for a single object of type T.
More...
#include <sync.hpp>
Public Member Functions | |
| template<typename... Args> | |
| T & | init (Args &&... args) |
| Constructs the contained object in-place. | |
| T & | get () |
| Returns a reference to the contained object. | |
| const T & | get () const |
| Returns a const reference to the contained object. | |
| bool | is_initialized () const |
Returns true if init() has been called successfully. | |
| StaticCell (const StaticCell &)=delete | |
| StaticCell & | operator= (const StaticCell &)=delete |
| StaticCell (StaticCell &&)=delete | |
| StaticCell & | operator= (StaticCell &&)=delete |
Thread-safe, lazily initialised storage cell for a single object of type T.
Holds the object in a properly aligned raw byte buffer so that no dynamic allocation is required. The object is placement-constructed by calling init() and its lifetime ends when the StaticCell is destroyed. A second call to init() aborts via assertion.
This is useful for zero-heap embedded targets where global objects with complex constructors must be initialised in a controlled order.
| T | The type of the object to store. Must be constructible with the arguments passed to init(). |
|
inline |
Constructs the contained object in-place.
Forwards all arguments to T's constructor. The initialisation flag is set atomically, ensuring the cell is initialised at most once.
| Args | Constructor argument types. |
| [in] | args | Arguments forwarded to T's constructor. |
|
inline |
Returns a reference to the contained object.
Asserts if init() has not been called yet.
|
inline |
Returns a const reference to the contained object.
Asserts if init() has not been called yet.
|
inline |
Returns true if init() has been called successfully.
true when the cell contains a live object.