nRF5 SDK v17.1.0
Data Structures | Macros | Typedefs | Functions
Doubly linked list API.

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]ptrPointer 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_headPointer 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]nameThe "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]nameThe "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_varVariable pointer name to return.
[in]ll_ptrPointer to the structure field.
[in]ll_typeName of the parent structure.
[in]ll_memberName 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]posIterator variable.
[in]headPointer 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_posIterator variable.
[out]ll_pos_nTemporary iterator variable (next entry).
[in]ll_headPointer to the list head.

Function Documentation

static void sys_list_add ( sys_list_head_t new,
sys_list_head_t head 
)
inlinestatic

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

Parameters
[in]newPointer to a new element.
[in]headPointer to the list head.
static void sys_list_add_tail ( sys_list_head_t new,
sys_list_head_t head 
)
inlinestatic

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

Parameters
[in]newPointer to a new element.
[in]headPointer to the list head.
static void sys_list_del ( sys_list_head_t entry)
inlinestatic

Function for deleting an entry from list.

Parameters
[in]entryThe element to delete from the list.
static void sys_list_del_init ( sys_list_head_t entry)
inlinestatic

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

Parameters
[in]entryThe element to delete from the list.
static unsigned int sys_list_empty ( sys_list_head_t head)
inlinestatic

Function for testing if a list is empty.

Parameters
[in]headThe 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 
)
inlinestatic

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_prevPointer to the previous element.
[in]l_nextPointer to the next element.
[in]l_newPointer to a new element.
static void sys_ll_list_del ( sys_list_head_t l_next,
sys_list_head_t l_prev 
)
inlinestatic

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_prevPointer to the previous element.
[in]l_nextPointer to the next element.

Documentation feedback | Developer Zone | Subscribe | Updated