Tenok
A Linux-like Real-Time Operating System for Robotics and Internet of Things
Data Structures | Macros | Functions
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...
 

Functions

void INIT_LIST_HEAD (struct list_head *list)
 Initialize the list head. More...
 
int list_empty (struct list_head *head)
 Check if the list is empty. More...
 
int list_is_last (const struct list_head *list, const struct list_head *head)
 Check if the list object is the last of the list. More...
 
void list_add (struct list_head *new, struct list_head *head)
 Add new list member to the list. More...
 
void list_del (struct list_head *entry)
 Delete a list item from its list. More...
 
void list_del_init (struct list_head *entry)
 Delete and force initialize a list member from its list. More...
 
void list_move (struct list_head *list, struct list_head *new_head)
 Move a list member from original list to another. 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.

Function Documentation

◆ INIT_LIST_HEAD()

void INIT_LIST_HEAD ( struct list_head list)

Initialize the list head.

Parameters
listList head to initialize.
Return values
None

◆ list_add()

void list_add ( struct list_head new,
struct list_head head 
)

Add new list member to the list.

Parameters
newNew list member.
headHead of the list.
Return values
None

◆ list_del()

void list_del ( struct list_head entry)

Delete a list item from its list.

Parameters
entryThe list member to delete.
Return values
None

◆ list_del_init()

void list_del_init ( struct list_head entry)

Delete and force initialize a list member from its list.

Parameters
entryThe list member to delete.
Return values
None

◆ list_empty()

int list_empty ( struct list_head head)

Check if the list is empty.

Parameters
headHead of the list.
Return values
int0 as false; otherwise true.

◆ list_is_last()

int list_is_last ( const struct list_head list,
const struct list_head head 
)

Check if the list object is the last of the list.

Parameters
listList member to check.
headHead of the list.
Return values
int0 as false, otherwise true.

◆ list_move()

void list_move ( struct list_head list,
struct list_head new_head 
)

Move a list member from original list to another.

Parameters
listThe list member to move.
new_headHead of the new list.
Return values
None