libtools
Classes | Macros
List macros

Lite list implementation from Linux kernel. More...

Collaboration diagram for List macros:

Classes

struct  list
 node of double-linked list More...
 

Macros

#define list_initializer(list)   { .prev = list, .next = list, }
 should be used to static initialization More...
 
#define list_init(list)
 should be used to runtime initialization More...
 
#define containerof(ptr, type, field)    ((type*)((size_t)(ptr) - offsetof(type, field)))
 return pointer to struct of type, which hold field More...
 
#define list_foreach(list, node, type, field)
 iterate over all list nodes More...
 
#define list_foreach_safe(l, i, t, type, f)
 iterate over all list nodes, also allow node deletion More...
 
#define list_add_head(list, node)
 add node to head of list More...
 
#define list_add_tail(list, node)
 add node to tail of list More...
 
#define list_del_node(node)
 remove node from list More...
 
#define list_is_empty(list)    ((list)->prev == (list) && (list) == (list)->next)
 expression is true, if list is empty More...
 

Detailed Description

Lite list implementation from Linux kernel.

Macro Definition Documentation

#define containerof (   ptr,
  type,
  field 
)    ((type*)((size_t)(ptr) - offsetof(type, field)))

return pointer to struct of type, which hold field

#define list_add_head (   list,
  node 
)
Value:
do { \
(node)->next = (list)->next; \
(node)->prev = (list); \
(list)->next->prev = (node); \
(list)->next = (node); \
} while(0); \
node of double-linked list
Definition: list.h:35

add node to head of list

#define list_add_tail (   list,
  node 
)
Value:
do { \
(node)->prev = (list)->prev; \
(node)->next = (list); \
(list)->prev->next = (node); \
(list)->prev = (node); \
} while(0); \
node of double-linked list
Definition: list.h:35

add node to tail of list

#define list_del_node (   node)
Value:
do { \
(node)->next->prev = (node)->prev; \
(node)->prev->next = (node)->next; \
(node)->prev = (node)->next = NULL; \
} while(0);

remove node from list

#define list_foreach (   list,
  node,
  type,
  field 
)
Value:
for((node) = containerof((list)->next, type, field); \
&(node)->field != (list); \
(node) = containerof((node)->field.next, type, field))
#define containerof(ptr, type, field)
return pointer to struct of type, which hold field
Definition: list.h:59
node of double-linked list
Definition: list.h:35

iterate over all list nodes

#define list_foreach_safe (   l,
  i,
  t,
  type,
 
)
Value:
for ( \
(i) = containerof((l)->next, type, f), \
(t) = containerof((i)->f.next, type, f); \
&(i)->f != (l); \
i = (t), (t) = containerof((t)->f.next, type, f) \
)
#define containerof(ptr, type, field)
return pointer to struct of type, which hold field
Definition: list.h:59

iterate over all list nodes, also allow node deletion

Parameters
[in]lpointer to struct list
[out]iiterator of list
[out]ttemporary pointer for safe list manipulation
[in]typetype of list
[in]fname of struct list field in type
#define list_init (   list)
Value:
do { \
(list)->prev = (list)->next = (list); \
} while (0)
node of double-linked list
Definition: list.h:35

should be used to runtime initialization

#define list_initializer (   list)    { .prev = list, .next = list, }

should be used to static initialization

#define list_is_empty (   list)    ((list)->prev == (list) && (list) == (list)->next)

expression is true, if list is empty