Doubly linked list API.

nRF5 SDK v13.0.0

Module to declare the doubly linked list API. More...

Data Structures

struct sys_list_head

Macros

#define LIST_HEAD_INIT (name)   { &(name), &(name) }
Initializes a list by variable name. More...
#define LIST_HEAD (name) sys_list_head_t name = { &(name), &(name) }
Defines and initializes a new list. More...
#define INIT_LIST_HEAD (ptr)
Initializes a list by pointer. More...
#define IS_EMPTY ( sys_list_head )   ( sys_list_head )->next == ( sys_list_head )
Checks if a list is empty. More...
#define SYS_LIST_ENTRY (ll_ret_var, ll_ptr, ll_type, ll_member)
Sets a pointer to a variable to the parent structure pointer using a pointer to a field in this structure. More...
#define SYS_LIST_FOR_EACH (pos, head)
Iterates through the list. More...
#define SYS_LIST_FOR_EACH_SAFE (ll_pos, ll_pos_n, ll_head)
Thread-safe version of SYS_LIST_FOR_EACH() . More...

Typedefs

typedef struct sys_list_head sys_list_head_t

Functions

static void sys_ll_list_add ( sys_list_head_t *l_prev, sys_list_head_t *l_next, sys_list_head_t *l_new)
Adds a new item to the list between l_prev and l_next elements. More...
static void sys_ll_list_del ( sys_list_head_t *l_next, sys_list_head_t *l_prev)
Deletes an element between l_prev and l_next elements. More...
static void sys_list_add ( sys_list_head_t *new, sys_list_head_t *head)
Function for adding a new item to the head of the list. More...
static void sys_list_add_tail ( sys_list_head_t *new, sys_list_head_t *head)
Function for adding a new item to the tail of the list. More...
static void sys_list_del ( sys_list_head_t *entry)
Function for deleting an entry from list. More...
static void sys_list_del_init ( sys_list_head_t *entry)
Function for deleting an entry from the list and reinitializing it. More...
static unsigned int sys_list_empty ( sys_list_head_t *head)
Function for testing if a list is empty. More...

Detailed Description

Module to declare the doubly linked list API.

Macro Definition Documentation

#define INIT_LIST_HEAD ( ptr )
Value:
do \
{ \
(ptr)->prev = (ptr); \
(ptr)->next = (ptr); \
} while (0)

Initializes a list by pointer.

Parameters
[in,out] ptr Pointer to a list.
#define IS_EMPTY ( sys_list_head ) ( sys_list_head )->next == ( sys_list_head )

Checks if a list is empty.

Parameters
[in] sys_list_head Pointer to a list.
Returns
0 if not empty, non-zero otherwise.
#define LIST_HEAD ( name ) sys_list_head_t name = { &(name), &(name) }

Defines and initializes a new list.

A call to this macro creates a new variable with the given name and initializes it as a list "head".

Parameters
[in,out] name The "head" struct name.
#define LIST_HEAD_INIT ( name ) { &(name), &(name) }

Initializes a list by variable name.

Warning
this macro assumes that a list "head" (sys_list_head_t) variable with name name is already created.
Parameters
[in,out] name The "head" struct name.
#define SYS_LIST_ENTRY ( ll_ret_var,
ll_ptr,
ll_type,
ll_member
)
Value:
do \
{ \
size_t p = (size_t) ll_ptr; \
size_t off = offsetof(ll_type, ll_member); \
ll_ret_var = (ll_type *) (p - off); \
} while (0)

Sets a pointer to a variable to the parent structure pointer using a pointer to a field in this structure.

Note
This is a version of GET_PARENT_BY_FIELD() extended by setting to a variable.
Parameters
[out] ll_ret_var Variable pointer name to return.
[in] ll_ptr Pointer to the structure field.
[in] ll_type Name of the parent structure.
[in] ll_member Name of the structure field.
#define SYS_LIST_FOR_EACH ( pos,
head
)
Value:
for (pos = ((head)->next); \
((pos) != (head)); \
pos = (pos)->next)

Iterates through the list.

Note
Use SYS_LIST_FOR_EACH_SAFE() for thread-safe cases.
Parameters
[out] pos Iterator variable.
[in] head Pointer to the list head.
#define SYS_LIST_FOR_EACH_SAFE ( ll_pos,
ll_pos_n,
ll_head
)
Value:
for (ll_pos = (ll_head)->next, ll_pos_n = (ll_head)->next->next; \
(ll_pos) != (ll_head); \
ll_pos = ll_pos_n, ll_pos_n = ll_pos->next)

Thread-safe version of SYS_LIST_FOR_EACH() .

Parameters
[out] ll_pos Iterator variable.
[out] ll_pos_n Temporary iterator variable (next entry).
[in] ll_head Pointer to the list head.

Function Documentation

static void sys_list_add ( sys_list_head_t * new ,
sys_list_head_t * head
)
inline static

Function for adding a new item to the head of the list.

Parameters
[in] new Pointer to a new element.
[in] head Pointer to the list head.
static void sys_list_add_tail ( sys_list_head_t * new ,
sys_list_head_t * head
)
inline static

Function for adding a new item to the tail of the list.

Parameters
[in] new Pointer to a new element.
[in] head Pointer to the list head.
static void sys_list_del ( sys_list_head_t * entry )
inline static

Function for deleting an entry from list.

Parameters
[in] entry The element to delete from the list.
static void sys_list_del_init ( sys_list_head_t * entry )
inline static

Function for deleting an entry from the list and reinitializing it.

Parameters
[in] entry The element to delete from the list.
static unsigned int sys_list_empty ( sys_list_head_t * head )
inline static

Function for testing if a list is empty.

Parameters
[in] head The list to test.
Returns
0 if not empty, non-zero otherwise.
static void sys_ll_list_add ( sys_list_head_t * l_prev ,
sys_list_head_t * l_next ,
sys_list_head_t * l_new
)
inline static

Adds a new item to the list between l_prev and l_next elements.

Warning
This routine assumes that l_next is next to l_prev in the list.
Note
This is an internal helper routine which is not intended to be used by the user.
Parameters
[in] l_prev Pointer to the previous element.
[in] l_next Pointer to the next element.
[in] l_new Pointer to a new element.
static void sys_ll_list_del ( sys_list_head_t * l_next ,
sys_list_head_t * l_prev
)
inline static

Deletes an element between l_prev and l_next elements.

Warning
This macro assumes that l_next is next to l_prev in the list.
Note
This is an internal helper routine which is not intended to be used by the user.
Parameters
[in] l_prev Pointer to the previous element.
[in] l_next Pointer to the next element.