µ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::intrusive_list< T, N, MP, U > Class Template Reference

List of intrusive nodes. More...

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

+ Inheritance diagram for os::utils::intrusive_list< T, N, MP, U >:

Public Types

using difference_type = ptrdiff_t
 
using iterator = intrusive_list_iterator< T, N, MP, U >
 
using iterator_pointer = N *
 Type of reference to the iterator internal pointer.
 
using pointer = U *
 
using reference = U &
 
using value_type = U
 

Public Member Functions

Constructors & Destructor
 intrusive_list ()
 Construct an intrusive list.
 
 intrusive_list (bool clr)
 Construct an intrusive list with controlled inits.
 
 ~intrusive_list ()
 Destruct the list.
 
Public Member Functions
void link (reference node)
 Add a node to the tail of the list.
 
iterator begin ()
 Iterator begin.
 
iterator end () const
 Iterator begin.
 
pointer unlink_head (void)
 Unlink the first element from the list.
 
pointer unlink_tail (void)
 Unlink the last element from 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

pointer get_pointer (iterator_pointer node) const
 
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

template<typename T, typename N, N T::* MP, typename U = T>
class os::utils::intrusive_list< T, N, MP, U >
Template Parameters
TType of object that includes the intrusive node.
NType of intrusive node. Must have the public members prev & next.
MPName of the intrusive node member in object T.
UType stored in the list, derived from T.
Examples
using threads_list = utils::intrusive_list<
thread, utils::double_list_links, &thread::child_links_>;
List of intrusive nodes.
Definition lists.h:690
Standard thread.

Definition at line 689 of file lists.h.

Member Typedef Documentation

◆ difference_type

template<typename T , typename N , N T::* MP, typename U = T>
using os::utils::intrusive_list< T, N, MP, U >::difference_type = ptrdiff_t

Definition at line 695 of file lists.h.

◆ iterator

template<typename T , typename N , N T::* MP, typename U = T>
using os::utils::intrusive_list< T, N, MP, U >::iterator = intrusive_list_iterator<T, N, MP, U>

Definition at line 697 of file lists.h.

◆ iterator_pointer

template<typename T , typename N , N T::* MP, typename U = T>
using os::utils::intrusive_list< T, N, MP, U >::iterator_pointer = N*

Definition at line 702 of file lists.h.

◆ pointer

template<typename T , typename N , N T::* MP, typename U = T>
using os::utils::intrusive_list< T, N, MP, U >::pointer = U*

Definition at line 693 of file lists.h.

◆ reference

template<typename T , typename N , N T::* MP, typename U = T>
using os::utils::intrusive_list< T, N, MP, U >::reference = U&

Definition at line 694 of file lists.h.

◆ value_type

template<typename T , typename N , N T::* MP, typename U = T>
using os::utils::intrusive_list< T, N, MP, U >::value_type = U

Definition at line 692 of file lists.h.

Constructor & Destructor Documentation

◆ intrusive_list() [1/2]

template<typename T , typename N , N T::* MP, typename U >
os::utils::intrusive_list< T, N, MP, U >::intrusive_list
inline

Definition at line 1135 of file lists.h.

1136 {
1137 }

◆ intrusive_list() [2/2]

template<typename T , typename N , N T::* MP, typename U >
os::utils::intrusive_list< T, N, MP, U >::intrusive_list ( bool  clr)
inline
Parameters
clrIf true, the list is cleared.

Definition at line 1140 of file lists.h.

1141 {
1142 if (clr)
1143 {
1144 clear ();
1145 }
1146 }
void clear(void)
Clear the list.
Definition lists.cpp:108

◆ ~intrusive_list()

template<typename T , typename N , N T::* MP, typename U >
os::utils::intrusive_list< T, N, MP, U >::~intrusive_list
inline

Definition at line 1149 of file lists.h.

1150 {
1151 }

Member Function Documentation

◆ begin()

template<typename T , typename N , N T::* MP, typename U >
intrusive_list< T, N, MP, U >::iterator os::utils::intrusive_list< T, N, MP, U >::begin
inline
Returns
An iterator positioned at the first element.
Note
It is not const because it may initialise on first use.

Definition at line 1185 of file lists.h.

1186 {
1187 if (uninitialized ())
1188 {
1189 // If this is the first time, initialise the list to empty.
1190 clear ();
1191 }
1192 return iterator{ static_cast<iterator_pointer> (head_.next ()) };
1193 }
intrusive_list_iterator< T, N, MP, U > iterator
Definition lists.h:697
N * iterator_pointer
Type of reference to the iterator internal pointer.
Definition lists.h:702
static_double_list_links head_
A list node used to point to head and tail.
Definition lists.h:473
bool uninitialized(void) const
Check if the list is uninitialised.
Definition lists.h:994

◆ clear()

void os::utils::static_double_list::clear ( void  )
inherited
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 }

References os::utils::static_double_list::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
inlineinherited

◆ end()

template<typename T , typename N , N T::* MP, typename U >
intrusive_list< T, N, MP, U >::iterator os::utils::intrusive_list< T, N, MP, U >::end
inline
Returns
An iterator positioned after the last element.

Definition at line 1197 of file lists.h.

1198 {
1199 return iterator{ static_cast<iterator_pointer> (
1200 const_cast<static_double_list_links*> (&head_)) };
1201 }

◆ get_pointer()

template<typename T , typename N , N T::* MP, typename U >
intrusive_list< T, N, MP, U >::pointer os::utils::intrusive_list< T, N, MP, U >::get_pointer ( iterator_pointer  node) const
inlineprotected

Definition at line 1207 of file lists.h.

1208 {
1209 // static_assert(std::is_convertible<U, T>::value == true, "U must be
1210 // implicitly convertible to T!");
1211
1212 // Compute the distance between the member intrusive link
1213 // node and the class begin.
1214 const auto offset = reinterpret_cast<difference_type> (
1215 &(static_cast<T*> (nullptr)->*MP));
1216
1217 // Compute the address of the object which includes the
1218 // intrusive node, by adjusting down the node address.
1219 return reinterpret_cast<pointer> (
1220 reinterpret_cast<difference_type> (node) - offset);
1221 }
ptrdiff_t difference_type
Definition lists.h:695

◆ head()

volatile static_double_list_links * os::utils::static_double_list::head ( void  ) const
inlineinherited
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 os::utils::static_double_list::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 
)
protectedinherited
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().

◆ link()

template<typename T , typename N , N T::* MP, typename U >
void os::utils::intrusive_list< T, N, MP, U >::link ( reference  node)
Parameters
[in]nodeReference to a list node.
Returns
Nothing.

Definition at line 1155 of file lists.h.

1156 {
1157 if (uninitialized ())
1158 {
1159 // If this is the first time, initialise the list to empty.
1160 clear ();
1161 }
1162
1163 // Compute the distance between the member intrusive link
1164 // node and the class begin.
1165 const auto offset = reinterpret_cast<difference_type> (
1166 &(static_cast<T*> (nullptr)->*MP));
1167
1168 // Add thread intrusive node at the end of the list.
1169 insert_after (*reinterpret_cast<static_double_list_links*> (
1170 reinterpret_cast<difference_type> (&node) + offset),
1171 const_cast<static_double_list_links*> (tail ()));
1172 }
void insert_after(static_double_list_links &node, static_double_list_links *after)
Insert a new node after existing node.
Definition lists.cpp:121
volatile static_double_list_links * tail(void) const
Get the list tail.
Definition lists.h:1014

◆ tail()

◆ uninitialized()

bool os::utils::static_double_list::uninitialized ( void  ) const
inlineinherited
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 os::utils::static_double_list::head_, and os::utils::static_double_list_links::prev().

◆ unlink_head()

template<typename T , typename N , N T::* MP, typename U >
intrusive_list< T, N, MP, U >::pointer os::utils::intrusive_list< T, N, MP, U >::unlink_head ( void  )
Returns
Pointer to the first element in the list.

Definition at line 1225 of file lists.h.

1226 {
1227 assert (!empty ());
1228
1229 // The first element in the list.
1230 iterator_pointer link = static_cast<iterator_pointer> (head_.next ());
1231 link->unlink ();
1232
1233 return get_pointer (link);
1234 }
pointer get_pointer(iterator_pointer node) const
Definition lists.h:1207
void link(reference node)
Add a node to the tail of the list.
Definition lists.h:1155
bool empty(void) const
Check if the list is empty.
Definition lists.h:1001

References link().

◆ unlink_tail()

template<typename T , typename N , N T::* MP, typename U >
intrusive_list< T, N, MP, U >::pointer os::utils::intrusive_list< T, N, MP, U >::unlink_tail ( void  )
Returns
Pointer to the last element in the list.

Definition at line 1238 of file lists.h.

1239 {
1240 assert (!empty ());
1241
1242 // The last element in the list.
1243 iterator_pointer link = static_cast<iterator_pointer> (head_.prev ());
1244 link->unlink ();
1245
1246 return get_pointer (link);
1247 }

References link().

Member Data Documentation

◆ head_


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