|
Embedded Artistry Framework
Embedded Systems C++ Framework
|
A linked list library for C modules. More...
|
Classes | |
| struct | ll_head |
| Linked list struct. More... | |
Macros | |
| #define | container_of(ptr, type, member) ((type*)((uintptr_t)(ptr)-offsetof(type, member))) |
| Define offsetof if we don't have it already. More... | |
Typedefs | |
| typedef struct ll_head | ll_t |
| Linked list struct. More... | |
Get Containers | |
| #define | list_entry(ptr, type, member) container_of(ptr, type, member) |
| Get the container for a list entry. More... | |
| #define | list_first_entry(head, type, member) list_entry((head)->next, type, member) |
| Get the container for the first item in the list. More... | |
Foreach Operations | |
| #define | list_for_each(pos, head) for(pos = (head)->next; pos != (head); pos = pos->next) |
| Declare a foreach loop which iterates over the list. More... | |
| #define | list_for_each_safe(pos, n, head) for(pos = (head)->next, n = pos->next; pos != (head); pos = n, n = pos->next) |
| Declare a foreach loop which iterates over the list, copy current node pointer. More... | |
| #define | list_for_each_entry(pos, head, member) |
| Declare a for loop which operates on each node in the list using the container value. More... | |
| #define | list_for_each_entry_safe(pos, n, head, member) |
| Declare a for loop which operates on each node in the list using a copy of the container value. More... | |
Initialization | |
| #define | ll_head_INIT(name) |
| Initialize a linked list so it points to itself. More... | |
| #define | LIST_INIT(name) struct ll_head name = ll_head_INIT(name) |
| Initialize a linked list. More... | |
Addition | |
| static void | list_insert (struct ll_head *n, struct ll_head *prev, struct ll_head *next) |
| Insert a new element between two existing elements. More... | |
| static void | list_add (struct ll_head *n, struct ll_head *head) |
| Add a node to the front of the list. More... | |
| static void | list_add_tail (struct ll_head *n, struct ll_head *head) |
| Add a node to the end of the list. More... | |
Deletion | |
| static void | list_join_nodes (struct ll_head *prev, struct ll_head *next) |
| Remove the node between two element pointers. More... | |
| static void | list_del (struct ll_head *entry) |
| Remove an entry from the list. More... | |
A linked list library for C modules.
| struct ll_head |
Define offsetof if we don't have it already.
Define container_of if we don't have it already
| #define list_entry | ( | ptr, | |
| type, | |||
| member | |||
| ) | container_of(ptr, type, member) |
Get the container for a list entry.
| [in] | ptr | The pointer to the target ll_t node. |
| [in] | type | The struct type which contains the ll_t node. For this example struct, type would refer to alloc_node_t: |
| [in] | member | The member which corresponds to the member name of the ll_t entry. For this example struct, member would refer to node. |
ptr, cast to type type. | #define list_first_entry | ( | head, | |
| type, | |||
| member | |||
| ) | list_entry((head)->next, type, member) |
Get the container for the first item in the list.
| [in] | head | The pointer to the head of the list. |
| [in] | type | The struct type which contains the ll_t node. For this example struct, type would refer to alloc_node_t: |
| [in] | member | The member which corresponds to the member name of the ll_t entry. For this example struct, member would refer to node. |
ptr, cast to type type. Declare a foreach loop which iterates over the list.
list_for_each() will run as long as the current object's next pointer is not equal to the head of the list. It's possible for a malformed list to loop forever.
| [in] | pos | The variable which will hold the current iteration's position value. This variable must be a pointer and should be pre-declared before instantiating the loop. |
| [in] | head | The head of of the linked list. Input should be a pointer. |
| #define list_for_each_entry | ( | pos, | |
| head, | |||
| member | |||
| ) |
Declare a for loop which operates on each node in the list using the container value.
| [in] | pos | The variable which will hold the current iteration's position value. This variable must be a pointer and should be pre-declared before instantiating the loop. The pos variable must be the container type. |
| [in] | head | The head of of the linked list. Input should be a pointer. |
| [in] | member | The member which corresponds to the member name of the ll_t entry. For this example struct, member would refer to node. |
| #define list_for_each_entry_safe | ( | pos, | |
| n, | |||
| head, | |||
| member | |||
| ) |
Declare a for loop which operates on each node in the list using a copy of the container value.
| [in] | pos | The variable which will hold the current iteration's position value. This variable must be a pointer and should be pre-declared before instantiating the loop. The pos variable must be the container type. |
| [in] | n | The variable which will hold the current iteration's position value copy. This variable must be a pointer and should be pre-declared before instantiating the loop. The n variable must be the container type. |
| [in] | head | The head of of the linked list. Input should be a pointer. |
| [in] | member | The member which corresponds to the member name of the ll_t entry. For this example struct, member would refer to node. |
| #define list_for_each_safe | ( | pos, | |
| n, | |||
| head | |||
| ) | for(pos = (head)->next, n = pos->next; pos != (head); pos = n, n = pos->next) |
Declare a foreach loop which iterates over the list, copy current node pointer.
list_for_each_safe() will run as long as the current object's next pointer is not equal to the head of the list. It's possible for a malformed list to loop forever.
The list_for_each_safe() variant makes a copy of the current node pointer, enabling the loop to get to the next pointer if there is a deletion.
| [in] | pos | The variable which will hold the current iteration's position value. This variable must be a pointer should be pre-declared before instantiating the loop. |
| [in] | n | The variable which will hold the current iteration's position value copy. This variable must be a pointer and should be pre-declared before instantiating the loop. |
| [in] | head | The head of of the linked list. Input should be a pointer. |
| #define LIST_INIT | ( | name | ) | struct ll_head name = ll_head_INIT(name) |
Initialize a linked list.
| [in] | name | The name of the linked list object to declare |
| #define ll_head_INIT | ( | name | ) |
Initialize a linked list so it points to itself.
| [in] | name | of the linked list object |
Linked list struct.
This is a doubly linked list structure. The ll_t structure should be embedded in a container structure that you want to list.
Example:
Add a node to the front of the list.
| [in] | n | The node to add to the list. |
| [in] | head | The head of the list. |
References list_insert(), n, and ll_head::next.
Referenced by malloc_addblock().
Add a node to the end of the list.
| [in] | n | The node to add to the list. |
| [in] | head | The head of the list. |
References list_insert(), n, and ll_head::prev.
Referenced by free().
|
inlinestatic |
Remove an entry from the list.
| [in] | entry | The pointer to the entry to remove from the list. |
References entry(), list_join_nodes(), and NULL.
Referenced by defrag_free_list(), and malloc().
|
inlinestatic |
Insert a new element between two existing elements.
| [in] | n | The node to add to the list. |
| [in] | prev | The pointer to the node before where the new node will be inserted. |
| [in] | next | The pointer to the new node after where the new node will be inserted. |
References n, ll_head::next, next, and ll_head::prev.
Referenced by free(), list_add(), list_add_tail(), and malloc().
Remove the node between two element pointers.
Joins the prev and next elements together, effectively removing the element in the middle.
| [in] | prev | The previous element in the list, which will now be joined to next. |
| [in] | next | The next element in the list, which will now be joined to prev. |
References ll_head::next, next, and ll_head::prev.
Referenced by list_del().
1.8.15