µOS++ IIIe Reference 7.0.0
The third edition of µOS++, a POSIX inspired open source framework, written in C++
Loading...
Searching...
No Matches
os::utils::static_double_list Class Reference

Statically allocated circular double linked list of nodes. More...

#include <cmsis-plus/utils/lists.h>

+ Inheritance diagram for os::utils::static_double_list:

Public Member Functions

Constructors & Destructor
 static_double_list ()
 Construct a list.
 
 ~static_double_list ()
 Destruct the list.
 
Public Member Functions
bool uninitialized (void) const
 Check if the list is uninitialised.
 
void clear (void)
 Clear the list.
 
bool empty (void) const
 Check if the list is empty.
 
volatile static_double_list_linkshead (void) const
 Get the list head.
 
volatile static_double_list_linkstail (void) const
 Get the list tail.
 

Protected Member Functions

Private Member Functions
void insert_after (static_double_list_links &node, static_double_list_links *after)
 Insert a new node after existing node.
 

Protected Attributes

Private Member Variables
static_double_list_links head_
 A list node used to point to head and tail.
 

Detailed Description

This is the simplest list, used as base class for scheduler lists that must be available for any statically constructed thread while still avoiding the 'static initialisation order fiasco'.

The idea 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.

This has the downside of requiring additional tests before adding new nodes to the list, to create the initial self links, and when checking if the list is empty.

Definition at line 341 of file lists.h.

Constructor & Destructor Documentation

◆ static_double_list()

os::utils::static_double_list::static_double_list ( )
inline

The initial list status is empty by having the pointers null.

Definition at line 979 of file lists.h.

980 {
981 // By all means, do not add any code here.
982 // The constructor was not `default` to benefit from inline.
983 }

◆ ~static_double_list()

os::utils::static_double_list::~static_double_list ( )
inline

There must be no nodes in the list.

Definition at line 989 of file lists.h.

990 {
991 }

Member Function Documentation

◆ clear()

void os::utils::static_double_list::clear ( void  )
Parameters
None.
Returns
Nothing.

Initialise the mandatory node with links to itself.

Definition at line 108 of file lists.cpp.

109 {
110#pragma GCC diagnostic push
111#if defined(__clang__)
112#elif defined(__GNUC__)
113#pragma GCC diagnostic ignored "-Wuseless-cast"
114#endif
115 head_.next (const_cast<static_double_list_links*> (&head_));
116 head_.prev (const_cast<static_double_list_links*> (&head_));
117#pragma GCC diagnostic pop
118 }
static_double_list_links head_
A list node used to point to head and tail.
Definition lists.h:473

References head_, os::utils::static_double_list_links::next(), and os::utils::static_double_list_links::prev().

Referenced by os::utils::double_list::double_list(), os::rtos::internal::ready_threads_list::link(), and os::rtos::internal::terminated_threads_list::link().

◆ empty()

bool os::utils::static_double_list::empty ( void  ) const
inline

◆ head()

volatile static_double_list_links * os::utils::static_double_list::head ( void  ) const
inline
Parameters
None.
Returns
Pointer to head node.

Definition at line 1008 of file lists.h.

1009 {
1010 return static_cast<volatile static_double_list_links*> (head_.next ());
1011 }

References head_, and os::utils::static_double_list_links::next().

◆ insert_after()

void os::utils::static_double_list::insert_after ( static_double_list_links node,
static_double_list_links after 
)
protected
Parameters
nodeReference to node to insert.
afterReference to existing node.
Returns
Nothing.

Definition at line 121 of file lists.cpp.

123 {
124#if defined(OS_TRACE_UTILS_LISTS)
125 trace::printf ("%s() n=%p after %p\n", __func__, &node, after);
126#endif
127
128 // Unlinked nodes must have both pointers null.
129 // If not, most probably the node was already linked.
130 // Or the memory is corrupted.
131 assert (node.prev () == nullptr);
132 assert (node.next () == nullptr);
133
134 // The `after` node must be linked. Only the `next` pointer is
135 // tested, since only it is used.
136 assert (after->next () != nullptr);
137
138 // Make the new node point to its neighbours.
139 node.prev (after);
140 node.next (after->next ());
141
142 // Make the neighbours point to the node. The order is important.
143 after->next ()->prev (&node);
144 after->next (&node);
145 }
int printf(const char *format,...)
Write a formatted string to the trace device.
Definition trace.cpp:59

References os::utils::static_double_list_links::next(), os::utils::static_double_list_links::prev(), and os::trace::printf().

Referenced by os::rtos::internal::thread_children_list::link(), os::rtos::internal::clock_timestamps_list::link(), os::rtos::internal::ready_threads_list::link(), os::rtos::internal::waiting_threads_list::link(), and os::rtos::internal::terminated_threads_list::link().

◆ tail()

volatile static_double_list_links * os::utils::static_double_list::tail ( void  ) const
inline

◆ uninitialized()

bool os::utils::static_double_list::uninitialized ( void  ) const
inline
Parameters
None.
Return values
trueThe list was not initialised.
falseThe list was initialised.

Definition at line 994 of file lists.h.

995 {
996 // If it points to nowhere, it is not yet initialised.
997 return (head_.prev () == nullptr);
998 }

References head_, and os::utils::static_double_list_links::prev().

Member Data Documentation

◆ head_


The documentation for this class was generated from the following files: