Tenok
A Linux-like Real-Time Operating System for Robotics and Internet of Things
Data Structures | Macros
list.h File Reference
#include <stddef.h>
Include dependency graph for list.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  list_head
 

Macros

#define container_of(ptr, type, member)    ((type *) ((void *) ptr - offsetof(type, member)))
 Get the object entry. More...
 
#define list_entry(ptr, type, member)   container_of(ptr, type, member)
 Get the object entry of a list. More...
 
#define list_first_entry(ptr, type, member)    list_entry((ptr)->next, type, member)
 Get the first object entry. More...
 
#define list_prev_entry(pos, member)    list_entry((pos)->member.prev, typeof(*(pos)), member)
 Get the previous object entry. More...
 
#define list_next_entry(pos, member)    list_entry((pos)->member.next, typeof(*(pos)), member)
 Get the next object entry. More...
 
#define list_entry_is_head(pos, head, member)   (&pos->member == (head))
 Check if the list entry is at the end of the list. More...
 
#define list_for_each(pos, head)    for ((pos) = (head)->next; (pos) != (head); (pos) = (pos)->next)
 Iterate the whole list with list pointer. More...
 
#define list_for_each_safe(pos, _next, head)
 Safely iterate the whole list with list pointer. More...
 
#define list_for_each_entry(pos, head, member)
 Iterate the whole list with list entry. More...
 
#define LIST_HEAD_INIT(name)
 Statically initialize the list head. More...
 
#define LIST_HEAD(name)   struct list_head name = LIST_HEAD_INIT(name)
 Declare and initialize a new list head. More...
 

Macro Definition Documentation

◆ container_of

#define container_of (   ptr,
  type,
  member 
)     ((type *) ((void *) ptr - offsetof(type, member)))

Get the object entry.

Parameters
ptrPointer to the structure member.
typeType of the object.
memberName of the structure member.
Return values
&objReturning object.

◆ list_entry

#define list_entry (   ptr,
  type,
  member 
)    container_of(ptr, type, member)

Get the object entry of a list.

Parameters
ptrPointer to the list member of the object.
typeType of the object.
memberName of the list member in the structure.
Return values
&objRetuning object.

◆ list_entry_is_head

#define list_entry_is_head (   pos,
  head,
  member 
)    (&pos->member == (head))

Check if the list entry is at the end of the list.

Parameters
posPosition of the object in the list.
memberName of the list member in the structure.
Return values
booltrue or false.

◆ list_first_entry

#define list_first_entry (   ptr,
  type,
  member 
)     list_entry((ptr)->next, type, member)

Get the first object entry.

Parameters
ptrHead of the list.
typeType of the object.
memberName of the list member in the structure.
Return values
&objRetunring object.

◆ list_for_each

#define list_for_each (   pos,
  head 
)     for ((pos) = (head)->next; (pos) != (head); (pos) = (pos)->next)

Iterate the whole list with list pointer.

Parameters
posCurrent position of the object in the list.
headHead of the list.
Return values
None

◆ list_for_each_entry

#define list_for_each_entry (   pos,
  head,
  member 
)
Value:
for (pos = list_first_entry(head, __typeof__(*pos), member); \
&pos->member != (head); pos = list_next_entry(pos, member))
#define list_first_entry(ptr, type, member)
Get the first object entry.
Definition: list.h:35
#define list_next_entry(pos, member)
Get the next object entry.
Definition: list.h:53

Iterate the whole list with list entry.

Parameters
posCurrent position of the object in the list.
headHead of the list.
memberName of the list member in the structure.
Return values
None

◆ list_for_each_safe

#define list_for_each_safe (   pos,
  _next,
  head 
)
Value:
for (pos = (head)->next, _next = (pos)->next; (pos) != (head); \
(pos) = _next, _next = (pos)->next)

Safely iterate the whole list with list pointer.

Parameters
posCurrent position of the object in the list.
headHead of the list.
Return values
None

◆ LIST_HEAD

#define LIST_HEAD (   name)    struct list_head name = LIST_HEAD_INIT(name)

Declare and initialize a new list head.

Parameters
nameName of the list head variable.
Return values
None

◆ LIST_HEAD_INIT

#define LIST_HEAD_INIT (   name)
Value:
{ \
.prev = (&name), .next = (&name) \
}

Statically initialize the list head.

Parameters
nameName of the list head variable.
Return values
None

◆ list_next_entry

#define list_next_entry (   pos,
  member 
)     list_entry((pos)->member.next, typeof(*(pos)), member)

Get the next object entry.

Parameters
posCurrent position of the object in the list.
memberName of the list member in the structure.
Return values
&objReturning object.

◆ list_prev_entry

#define list_prev_entry (   pos,
  member 
)     list_entry((pos)->member.prev, typeof(*(pos)), member)

Get the previous object entry.

Parameters
posCurrent position of the object in the list.
memberName of the list member in the structure.
Return values
&objReturning object.