utils-lists 4.0.0
µOS++ C++ intrusive lists utilities
|
A class for the core of a statically allocated double linked list (pointers to neighbours). More...
#include <micro-os-plus/utils/lists.h>
Public Types | |
using | is_statically_allocated = std::true_type |
Type indicating that the links node is statically allocated. | |
Public Member Functions | |
constexpr | static_double_list_links () |
Construct a statically allocated list node (bss initialised). | |
constexpr | ~static_double_list_links () |
Destruct the node. | |
constexpr void | initialize (void) |
Initialise the node links. | |
void | initialize_once (void) |
Initialize the list only at first run. | |
void | link_next (double_list_links_base *node) |
Link the new node as next. | |
void | link_previous (double_list_links_base *node) |
Link the new node as previous. | |
bool | linked (void) const |
Check if the node is linked to a double list. | |
constexpr double_list_links_base * | next (void) const |
Get the link to the next node. | |
void | nullify (void) |
Reset the two pointers to nullptr . | |
constexpr double_list_links_base * | previous (void) const |
Get the link to the previous node. | |
bool | uninitialized (void) const |
Check if the node is uninitialised. | |
void | unlink (void) |
Remove this node from the list. | |
Protected Attributes | |
double_list_links_base * | next_ |
Pointer to the next node. | |
double_list_links_base * | previous_ |
Pointer to the previous node. | |
A class for the core of a statically allocated double linked list (pointers to neighbours).
The pair of uninitialised pointers to the next and previous list elements and the methods to access the pointers are inherited from the base class.
It is expected that instances of this class to be statically allocated in the bss section and cleared (set to zero) during startup.
These peculiar types of lists are used by registrars, to automate the self-registration of other statically allocated objects, like drivers, threads, etc.
Since the order of static constructors is not defined, it is perfectly and legally possible that the constructor of the registrar will be invoked after the constructors of the objects that need to register into the list, thus the registrar must be guaranteed to be initialised before running any static constructors.
The solution is to design the object in such a way as to benefit from the standard bss initialisation, in other words take nullptr
as starting values.
In practical terms, the list initialisation cannot be done in the constructor, but must be manually done before any method that adds elements to the list is called.
using micro_os_plus::utils::static_double_list_links::is_statically_allocated = std::true_type |
|
constexpr |
Construct a statically allocated list node (bss initialised).
As the name implies, it is assumed that the instance of the object is allocated statically and the entire content was set to zero during startup (via BSS init).
This is equivalent to setting the pointers to nullptr
.
|
constexpr |
|
constexprinherited |
|
inherited |
Initialize the list only at first run.
If the statically allocated list is still in the initial uninitialised state (with both pointers nullptr
), initialise the list to the empty state, with both pointers pointing to itself.
For non-statically initialised lists, this method is ineffective, since the node is always initialised at construct time.
|
inherited |
|
inherited |
|
inherited |
|
constexprinherited |
void micro_os_plus::utils::static_double_list_links::nullify | ( | void | ) |
|
constexprinherited |
|
inherited |
Check if the node is uninitialised.
true | The links are not initialised. |
false | The links are initialised. |
An uninitialized node is a node with the pointers set to nullptr
.
Only statically allocated nodes in the initial state are uninitialized. Regular nodes are always initialised.
|
inherited |
|
protectedinherited |
|
protectedinherited |