Intrusive circular doubly linked list.
More...
#include "container_of.h"
#include <assert.h>
#include <stdbool.h>
#include <stddef.h>
Go to the source code of this file.
|
#define | list_node_entry(ptr, type, member) |
| Obtain a pointer to the struct that contains the list node as a member.
|
|
Intrusive circular doubly linked list.
Inspired by:
◆ list_node_entry
#define list_node_entry |
( |
| ptr, |
|
|
| type, |
|
|
| member ) |
Value:
#define container_of(ptr, type, member)
Obtain a pointer to the struct that contains the member.
Definition container_of.h:34
Obtain a pointer to the struct that contains the list node as a member.
- Parameters
-
[in] | ptr | Node pointer. |
[in] | type | Container type. |
[in] | member | Node member name. |
- Returns
- A pointer to the struct containing the node member.
◆ list_node_add_after()
static void list_node_add_after |
( |
struct list_node * | node_ptr, |
|
|
struct list_node * | prev_ptr ) |
|
inlinestatic |
Add a node after the given node.
- Note
- This can be used to construct a stack.
- Parameters
-
[in] | prev_ptr | The prev node pointer. |
[in] | node_ptr | The node pointer. |
◆ list_node_add_before()
static void list_node_add_before |
( |
struct list_node * | node_ptr, |
|
|
struct list_node * | next_ptr ) |
|
inlinestatic |
Add a node before the given node.
- Note
- This can be used to construct a queue.
- Parameters
-
[in] | next_ptr | The next node pointer. |
[in] | node_ptr | The node pointer. |
◆ list_node_init()
static void list_node_init |
( |
struct list_node * | node_ptr | ) |
|
|
inlinestatic |
Initialize a list node.
- Parameters
-
[in] | node_ptr | The node pointer. |
◆ list_node_is_first()
static bool list_node_is_first |
( |
const struct list_node * | node_ptr, |
|
|
const struct list_node * | head_ptr ) |
|
inlinestatic |
Check if a given list node is first in the list (aka after the head).
- Parameters
-
[in] | node_ptr | The node pointer. |
[in] | head_ptr | The head node pointer. |
- Returns
- Whether the list node is first in the list.
◆ list_node_is_head()
static bool list_node_is_head |
( |
const struct list_node * | node_ptr, |
|
|
const struct list_node * | head_ptr ) |
|
inlinestatic |
Check if a given list node is the head of the list.
- Parameters
-
[in] | node_ptr | The node pointer. |
[in] | head_ptr | The head node pointer. |
- Returns
- Whether the list node is head of the list.
◆ list_node_is_last()
static bool list_node_is_last |
( |
const struct list_node * | node_ptr, |
|
|
const struct list_node * | tail_ptr ) |
|
inlinestatic |
Check if a given list node is the last of the list (aka before the tail).
- Parameters
-
[in] | node_ptr | The node pointer. |
[in] | tail_ptr | The tail node pointer. |
- Returns
- Whether the list node is the last in the list.
◆ list_node_is_tail()
static bool list_node_is_tail |
( |
const struct list_node * | node_ptr, |
|
|
const struct list_node * | tail_ptr ) |
|
inlinestatic |
Check if a given list node is the tail of the list.
- Parameters
-
[in] | node_ptr | The node pointer. |
[in] | tail_ptr | The tail node pointer. |
- Returns
- Whether the list node is the tail of the list.
◆ list_node_remove()
Remove a node and deattach it from the list it resides in.
Assumes:
- node_ptr node is a part of a list.
- node_ptr node is not the head or tail node.
- Parameters
-
[in] | node_ptr | The node pointer. |
- Returns
- Pointer to the removed node
◆ list_node_replace()
Replace a given node by a new node.
Assumes:
- The node is a part of a list.
- The node is not the head or tail node (points to self).
- Parameters
-
[in] | old_ptr | Pointer to old node. |
[in] | new_ptr | Pointer to new node. |