Skip to main content

The intrusive_list Class Template Reference

A class template for a list of nodes which store the links inside themselves as intrusive nodes. More...

Declaration

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
class micro_os_plus::utils::intrusive_list<T, N, MP, L, U>;

Included Headers

Base class

classdouble_list<T, L>

A class template for a doubly linked list of nodes. More...

Public Member Typedefs Index

usingdifference_type = ptrdiff_t

Type of pointer difference. More...

usingis_statically_allocated = typename links_type::is_statically_allocated

Type indicating if the links node is statically allocated. More...

usingiterator = intrusive_list_iterator< T, N, MP, U >

Type of iterator over the values. More...

usingiterator_pointer = N *

Type of reference to the iterator internal pointer. More...

usinglinks_type = L

Type of the list links node object where the pointers to the list head and tail are stored. More...

usingpointer = value_type *

Type of pointer to object pointed to by the iterator. More...

usingreference = value_type &

Type of reference to object pointed to by the iterator. More...

usingvalue_type = U

Type of value pointed to by the iterator. More...

Public Constructors Index

constexprintrusive_list ()

Construct an intrusive doubly linked list. More...

 intrusive_list (const intrusive_list &)=delete

Deleted copy constructor. More...

 intrusive_list (intrusive_list &&)=delete

Deleted move constructor. More...

Public Destructor Index

constexpr~intrusive_list ()

Destruct the list. More...

Public Member Functions Index

iteratorbegin () const

Iterator begin. More...

voidclear (void)

Clear the list. More...

constexpr boolempty (void) const

Check if the list is empty. More...

iteratorend () const

Iterator begin. More...

constexpr pointerhead (void) const

Get the list head. More...

voidinitialize_once (void)

Initialize the list only at first run. More...

voidlink_head (reference node)

Add a node to the head of the list. More...

voidlink_tail (reference node)

Add a node to the tail of the list. More...

constexpr const links_type *links_pointer (void) const

Get the address of the node storing the list links. More...

intrusive_list &operator= (const intrusive_list &)=delete

Deleted copy assignment operator. More...

intrusive_list &operator= (intrusive_list &&)=delete

Deleted move assignment operator. More...

constexpr pointertail (void) const

Get the list tail. More...

booluninitialized (void) const

Check if the list is uninitialised (only statically allocated lists can be uninitialised). More...

pointerunlink_head (void)

Unlink the first element from the list. More...

pointerunlink_tail (void)

Unlink the last element from the list. More...

Protected Member Functions Index

pointerget_pointer (iterator_pointer node) const

Get the address of the object from the intrusive node pointer. More...

Protected Member Attributes Index

links_typelinks_

The list top node used to point to head and tail nodes. More...

Description

A class template for a list of nodes which store the links inside themselves as intrusive nodes.

Template Parameters
TType of object that includes the intrusive node.
NType of intrusive node with the next & previous links.
MPName of the intrusive node member in object T.
LType of the links node (one of double_list_links or static_double_list_links).
UType stored in the list, derived from T.

This class implements an intrusive doubly linked list, where each object stores its own link node as a member. The list maintains a pair of head and tail pointers, allowing efficient insertion, removal, and iteration. The intrusive approach eliminates the need for separate node allocations, as the links are embedded within the objects themselves.

The template parameter MP specifies the member pointer to the intrusive node within the object, enabling the list to compute the address of the parent object from the node pointer. This design supports both regular and statically allocated lists, depending on the type used for L.

Iterators provide access to the objects in the list, supporting bidirectional traversal.

Example
 namespace os = micro_os_plus;
 using threads_list = os::utils::intrusive_list<
  thread, os::utils::double_list_links, &thread::child_links_>;

For statically allocated lists, set L=static_double_list_links.

Definition at line 1135 of file lists.h.

Public Member Typedefs

difference_type

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
using micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::difference_type = ptrdiff_t

Type of pointer difference.

Definition at line 1183 of file lists.h.

is_statically_allocated

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
using micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::is_statically_allocated = typename links_type::is_statically_allocated

Type indicating if the links node is statically allocated.

Definition at line 1172 of file lists.h.

iterator

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
using micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::iterator = intrusive_list_iterator<T, N, MP, U>

Type of iterator over the values.

Definition at line 1167 of file lists.h.

iterator_pointer

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
using micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::iterator_pointer = N*

Type of reference to the iterator internal pointer.

Definition at line 1178 of file lists.h.

links_type

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
using micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::links_type = L

Type of the list links node object where the pointers to the list head and tail are stored.

Definition at line 1147 of file lists.h.

pointer

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
using micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::pointer = value_type*

Type of pointer to object pointed to by the iterator.

Definition at line 1157 of file lists.h.

reference

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
using micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::reference = value_type&

Type of reference to object pointed to by the iterator.

Definition at line 1162 of file lists.h.

value_type

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
using micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::value_type = U

Type of value pointed to by the iterator.

Definition at line 1152 of file lists.h.

Public Constructors

intrusive_list()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::intrusive_list ()
constexpr

Construct an intrusive doubly linked list.

The default constructor for intrusive_list creates an empty intrusive list. No initialisation of internal pointers is performed here; for statically allocated lists, the pointers are expected to be zero-initialised by the runtime, while for dynamically allocated lists, initialisation is handled by the base class or explicit methods.

The rule of five

The copy constructor, move constructor, copy assignment operator, and move assignment operator are explicitly deleted to prevent accidental copying or moving of intrusive_list objects. This ensures the integrity of the list structure, as duplicating or moving lists could result in invalid or inconsistent links within the list.

Declaration at line 1188 of file lists.h, definition at line 961 of file lists-inlines.h.

intrusive_list()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::intrusive_list (const intrusive_list &)
delete

Deleted copy constructor.

Copying of intrusive_list instances is explicitly disallowed to prevent accidental duplication, which could compromise the integrity of the list structure.

Definition at line 1200 of file lists.h.

intrusive_list()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::intrusive_list (intrusive_list &&)
delete

Deleted move constructor.

Moving of intrusive_list instances is explicitly disallowed to avoid invalid or inconsistent links within the list that could result from moving lists.

Definition at line 1210 of file lists.h.

Public Destructor

~intrusive_list()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::~intrusive_list ()
constexpr

Destruct the list.

The destructor for intrusive_list does not perform any cleanup or pointer manipulation. List management and node unlinking are handled elsewhere, so the destructor is intentionally left empty to avoid unnecessary writes or side effects during object destruction.

Declaration at line 1238 of file lists.h, definition at line 973 of file lists-inlines.h.

Public Member Functions

begin()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
intrusive_list< T, N, MP, L, U >::iterator micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::begin () const
inline

Iterator begin.

Returns

An iterator positioned at the first element.

Returns an iterator to the first element in the intrusive list. The iterator points to the node after the internal links node (the head). For statically allocated lists, the initialisation check is handled by the links class. If the list is empty, the iterator will compare equal to end().

Declaration at line 1311 of file lists.h, definition at line 1076 of file lists-inlines.h.

clear()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
void micro_os_plus::utils::double_list< N, double_list_links >::clear (void)

Clear the list.

Parameters

None.

Returns

Nothing.

The clear() method initialises the mandatory internal links node so that both its previous_ and next_ pointers refer to itself. This marks the list as empty and ensures it is in a safe, known state, ready for new insertions. This operation is typically used to reset the list, removing all elements and breaking any existing links.

Declaration at line 816 of file lists.h, definition at line 601 of file lists-inlines.h.

empty()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
bool micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::empty (void) const
constexpr

Check if the list is empty.

Parameters

None.

Return Values
trueThe list has no nodes.
falseThe list has at least one node.

Checks whether the intrusive list contains any nodes. This method delegates to the underlying double list implementation to determine if the list is empty. The list is considered empty if there are no elements linked.

Declaration at line 1261 of file lists.h, definition at line 1004 of file lists-inlines.h.

end()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
intrusive_list< T, N, MP, L, U >::iterator micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::end () const
inline

Iterator begin.

Returns

An iterator positioned after the last element.

Returns an iterator to the position after the last element in the intrusive list (the end iterator). This iterator points to the internal links node, which acts as a sentinel. It is used as the past-the-end marker in iteration and comparison operations. The end iterator does not reference any valid list element.

Declaration at line 1319 of file lists.h, definition at line 1094 of file lists-inlines.h.

head()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
double_list< N, double_list_links >::pointer micro_os_plus::utils::double_list< N, double_list_links >::head (void) const
constexpr

Get the list head.

Parameters

None.

Returns

Pointer to the head node.

Returns a pointer to the first node in the list. If the list is empty, this will point to the internal links node itself, which can be used to detect the end of the list during iteration. The returned pointer should be checked against end() or the sentinel node to determine if the list contains any elements.

Declaration at line 826 of file lists.h, definition at line 619 of file lists-inlines.h.

initialize_once()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
void micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::initialize_once (void)

Initialize the list only at first run.

Parameters

None.

Returns

Nothing.

If the statically allocated list is still in the initial uninitialised state (with both pointers null), this method initialises the list to the empty state, with both pointers pointing to itself. For non-statically initialised lists, this method has no effect.

info

Must be manually called for statically allocated lists before inserting elements or performing any other operations.

Declaration at line 1250 of file lists.h, definition at line 990 of file lists-inlines.h.

link_head()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
void micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::link_head (reference node)

Add a node to the head of the list.

Parameters
[in] nodeReference to a list node.
Returns

Nothing.

Adds a new node to the beginning (head) of the intrusive list. The offset of the intrusive node member within the containing object is computed, and the node is linked before the current head node. This operation does not check for duplicate nodes or whether the node is already linked elsewhere. For statically allocated lists, the initialisation check is handled by the links class.

Declaration at line 1281 of file lists.h, definition at line 1046 of file lists-inlines.h.

link_tail()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
void micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::link_tail (reference node)

Add a node to the tail of the list.

Parameters
[in] nodeReference to a list node.
Returns

Nothing.

Adds a new node to the end (tail) of the intrusive list. The offset of the intrusive node member within the containing object is computed, and the node is linked after the current tail node. This operation does not check for duplicate nodes or whether the node is already linked elsewhere. For statically allocated lists, the initialisation check is handled by the links class.

Declaration at line 1271 of file lists.h, definition at line 1020 of file lists-inlines.h.

links_pointer()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
const links_type * micro_os_plus::utils::double_list< N, double_list_links >::links_pointer (void) const
inlineconstexpr

Get the address of the node storing the list links.

Parameters

None.

Returns

A pointer to the list head object.

Definition at line 886 of file lists.h.

operator=()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
intrusive_list & micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::operator= (const intrusive_list &)
delete

Deleted copy assignment operator.

Copy assignment is explicitly disallowed to prevent accidental overwriting of list objects, which could lead to corruption of the list structure.

Definition at line 1221 of file lists.h.

operator=()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
intrusive_list & micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::operator= (intrusive_list &&)
delete

Deleted move assignment operator.

Move assignment is explicitly disallowed to avoid invalid or inconsistent links within the list that could result from moving lists.

Definition at line 1232 of file lists.h.

tail()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
double_list< N, double_list_links >::pointer micro_os_plus::utils::double_list< N, double_list_links >::tail (void) const
constexpr

Get the list tail.

Parameters

None.

Returns

Pointer to the tail node.

Returns a pointer to the last node in the list. If the list is empty, this will point to the internal links node itself, which can be used to detect the end of the list during reverse iteration. The returned pointer should be checked against the sentinel node to determine if the list contains any elements.

Declaration at line 836 of file lists.h, definition at line 634 of file lists-inlines.h.

uninitialized()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
bool micro_os_plus::utils::double_list< N, double_list_links >::uninitialized (void) const

Check if the list is uninitialised (only statically allocated lists can be uninitialised).

Parameters

None.

Return Values
trueThe list was not initialised.
falseThe list was initialised.

An uninitialized node is a node with any of the pointers set to nullptr. Only statically allocated nodes in the initial state are considered uninitialized. For dynamically allocated lists, this method always returns false since their nodes are explicitly initialized during construction.

Declaration at line 783 of file lists.h, definition at line 542 of file lists-inlines.h.

unlink_head()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
intrusive_list< T, N, MP, L, U >::pointer micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::unlink_head (void)

Unlink the first element from the list.

Parameters

None.

Returns

Pointer to the first element in the list.

Removes and unlinks the first element from the intrusive list. If the list is empty, this operation is a no-op and returns a pointer to the internal links node. The method unlinks the node at the head of the list and returns a pointer to the parent object containing the unlinked node.

Declaration at line 1301 of file lists.h, definition at line 1145 of file lists-inlines.h.

unlink_tail()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
intrusive_list< T, N, MP, L, U >::pointer micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::unlink_tail (void)

Unlink the last element from the list.

Parameters

None.

Returns

Pointer to the last element in the list.

Removes and unlinks the last element from the intrusive list. If the list is empty, this operation is a no-op and returns a pointer to the internal links node. The method unlinks the node at the tail of the list and returns a pointer to the parent object containing the unlinked node.

Declaration at line 1291 of file lists.h, definition at line 1167 of file lists-inlines.h.

Protected Member Functions

get_pointer()

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
intrusive_list< T, N, MP, L, U >::pointer micro_os_plus::utils::intrusive_list< T, N, MP, L, U >::get_pointer (iterator_pointer node) const
inlineprotected

Get the address of the object from the intrusive node pointer.

Parameters
nodePointer to the intrusive node.
Returns

A pointer to the parent object containing the node.

Computes and returns a pointer to the parent object that contains the intrusive node referenced by the given node pointer. This is achieved by calculating the offset of the intrusive node member within the parent object type and subtracting it from the node's address. This allows retrieval of the full object from just the node pointer, enabling intrusive list traversal and manipulation.

Declaration at line 1330 of file lists.h, definition at line 1119 of file lists-inlines.h.

Protected Member Attributes

links_

template <class T, class N, N T::* MP, class L = double_list_links, class U = T>
links_type micro_os_plus::utils::double_list< N, double_list_links >::links_
protected

The list top node used to point to head and tail nodes.

This member stores the internal links node for the list. The next pointer of this node points to the head of the list, and the previous pointer points to the tail. For an empty list, both pointers refer to the node itself, simplifying list management and boundary checks.

Definition at line 904 of file lists.h.


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


Generated via docusaurus-plugin-doxygen by Doxygen 1.13.2