![]() |
SuperTinyKernel™ RTOS 1.06.0
Lightweight, high-performance, deterministic, bare-metal C++ RTOS for resource-constrained embedded systems. MIT Open Source License.
|
Intrusive doubly-linked list container. Manages a collection of DListEntry nodes embedded in host objects of type T. More...
#include <stk_linked_list.h>
Public Types | |
| typedef DListEntry< T, _ClosedLoop > | DLEntryType |
| Convenience alias for the node type stored in this list. | |
Public Member Functions | |
| DListHead () | |
| Construct an empty list head (count = 0, first = last = NULL). | |
| size_t | GetSize () const |
| Get the number of entries currently in the list. | |
| bool | IsEmpty () const |
| Check whether the list contains no entries. | |
| DLEntryType * | GetFirst () const |
| Get the first (front) entry without removing it. | |
| DLEntryType * | GetLast () const |
| Get the last (back) entry without removing it. | |
| void | Clear () |
| Remove and unlink all entries. After this call the list is empty. | |
| void | LinkBack (DLEntryType *entry) |
| Append entry to the back of the list (pointer overload). | |
| void | LinkBack (DLEntryType &entry) |
| Append entry to the back of the list (reference overload). | |
| void | LinkFront (DLEntryType *entry) |
| Prepend entry to the front of the list (pointer overload). | |
| void | LinkFront (DLEntryType &entry) |
| Prepend entry to the front of the list (reference overload). | |
| DLEntryType * | PopBack () |
| Remove and return the last entry. | |
| DLEntryType * | PopFront () |
| Remove and return the first entry. | |
| void | Unlink (DLEntryType *entry) |
| Remove entry from this list. | |
| void | RelinkTo (DListHead &to) |
| Move all entries from this list to the back of to, preserving order. | |
| void | Link (DLEntryType *entry, DLEntryType *next=nullptr, DLEntryType *prev=nullptr) |
| Insert entry into the list between prev and next. | |
Private Member Functions | |
| void | UpdateEnds () |
| Repair the boundary and circular pointers after every structural change. | |
Private Attributes | |
| size_t | m_count |
| Number of entries currently in the list. | |
| DLEntryType * | m_first |
Pointer to the first (front) entry, or NULL when empty. | |
| DLEntryType * | m_last |
Pointer to the last (back) entry, or NULL when empty. | |
Friends | |
| class | DListEntry< T, _ClosedLoop > |
Intrusive doubly-linked list container. Manages a collection of DListEntry nodes embedded in host objects of type T.
| T | The host class whose instances are stored in this list. Each T must derive from DListEntry<T, _ClosedLoop>. |
| _ClosedLoop | When true the list is maintained as a circular ring: after every insertion or removal, last->next is set to first and first->prev is set to last. This allows scheduler algorithms to wrap around the end of the list in O(1) without a branch. When false the boundary pointers remain NULL (standard open list). |
NULL to Unlink() and trigger an assertion. Guard with IsEmpty(). Definition at line 195 of file stk_linked_list.h.
| typedef DListEntry<T, _ClosedLoop> stk::util::DListHead< T, _ClosedLoop >::DLEntryType |
Convenience alias for the node type stored in this list.
Definition at line 203 of file stk_linked_list.h.
|
inlineexplicit |
Construct an empty list head (count = 0, first = last = NULL).
Definition at line 207 of file stk_linked_list.h.
References m_count, m_first, and m_last.
Referenced by RelinkTo().
|
inline |
Remove and unlink all entries. After this call the list is empty.
Definition at line 234 of file stk_linked_list.h.
References IsEmpty(), m_first, and Unlink().
|
inline |
Get the first (front) entry without removing it.
NULL if the list is empty. Definition at line 223 of file stk_linked_list.h.
References m_first.
Referenced by stk::SchedulabilityCheck::IsSchedulableWCRT().
|
inline |
Get the last (back) entry without removing it.
NULL if the list is empty. Definition at line 228 of file stk_linked_list.h.
References m_last.
|
inline |
Get the number of entries currently in the list.
Definition at line 213 of file stk_linked_list.h.
References m_count.
Referenced by stk::SchedulabilityCheck::IsSchedulableWCRT().
|
inline |
Check whether the list contains no entries.
true if empty; false otherwise. Definition at line 218 of file stk_linked_list.h.
References m_count.
Referenced by Clear(), RelinkTo(), and UpdateEnds().
|
inline |
Insert entry into the list between prev and next.
| [in] | entry | Entry to insert. Must be non-NULL and not currently linked. |
| [in] | next | Entry that will follow entry after insertion, or NULL to append. |
| [in] | prev | Entry that will precede entry after insertion, or NULL to prepend. |
NULL the method treats this as a front-insertion: next is overridden to m_first so entry becomes the new first element. Definition at line 330 of file stk_linked_list.h.
References stk::util::DListEntry< T, _ClosedLoop >::GetNext(), stk::util::DListEntry< T, _ClosedLoop >::GetPrev(), stk::util::DListEntry< T, _ClosedLoop >::IsLinked(), stk::util::DListEntry< T, _ClosedLoop >::Link(), m_count, m_first, m_last, STK_ASSERT, and UpdateEnds().
Referenced by LinkBack(), LinkBack(), LinkFront(), and LinkFront().
|
inline |
|
inline |
Append entry to the back of the list (pointer overload).
| [in] | entry | Entry to insert. Must not already be linked to any list. |
Definition at line 239 of file stk_linked_list.h.
References Link(), and m_last.
Referenced by RelinkTo().
|
inline |
|
inline |
Prepend entry to the front of the list (pointer overload).
| [in] | entry | Entry to insert. Must not already be linked to any list. |
Definition at line 251 of file stk_linked_list.h.
References Link(), and m_last.
|
inline |
Remove and return the last entry.
NULL). Always check IsEmpty() before calling. Definition at line 263 of file stk_linked_list.h.
References m_last, and Unlink().
|
inline |
Remove and return the first entry.
NULL). Always check IsEmpty() before calling. Definition at line 275 of file stk_linked_list.h.
References m_first, and Unlink().
Referenced by RelinkTo().
|
inline |
Move all entries from this list to the back of to, preserving order.
| [in] | to | Destination list. Must not be the same object as *this. |
*this is empty and every entry that was here is now at the back of to, in the same relative order. *this. Definition at line 311 of file stk_linked_list.h.
References DListHead(), IsEmpty(), LinkBack(), PopFront(), and STK_ASSERT.
|
inline |
Remove entry from this list.
| [in] | entry | Entry to remove. Must be non-NULL, currently linked, and owned by this list. |
Definition at line 287 of file stk_linked_list.h.
References stk::util::DListEntry< T, _ClosedLoop >::GetHead(), stk::util::DListEntry< T, _ClosedLoop >::GetNext(), stk::util::DListEntry< T, _ClosedLoop >::GetPrev(), stk::util::DListEntry< T, _ClosedLoop >::IsLinked(), m_count, m_first, m_last, STK_ASSERT, stk::util::DListEntry< T, _ClosedLoop >::Unlink(), and UpdateEnds().
Referenced by Clear(), PopBack(), and PopFront().
|
inlineprivate |
Repair the boundary and circular pointers after every structural change.
NULL so the head is in a canonical empty state._ClosedLoop is true and the list is non-empty, sets m_last->m_next = m_first and m_first->m_prev = m_last to maintain the circular invariant. _ClosedLoop == false) only the empty-list reset runs; the branch is eliminated at compile time by the constant template parameter. Definition at line 362 of file stk_linked_list.h.
References IsEmpty(), m_first, and m_last.
Referenced by Link(), and Unlink().
|
friend |
Definition at line 172 of file stk_linked_list.h.
|
private |
Number of entries currently in the list.
Definition at line 377 of file stk_linked_list.h.
Referenced by DListHead(), GetSize(), IsEmpty(), Link(), and Unlink().
|
private |
Pointer to the first (front) entry, or NULL when empty.
Definition at line 378 of file stk_linked_list.h.
Referenced by Clear(), DListHead(), GetFirst(), Link(), PopFront(), Unlink(), and UpdateEnds().
|
private |
Pointer to the last (back) entry, or NULL when empty.
Definition at line 379 of file stk_linked_list.h.
Referenced by DListHead(), GetLast(), Link(), LinkBack(), LinkBack(), LinkFront(), LinkFront(), PopBack(), Unlink(), and UpdateEnds().