Tenok
A Linux-like Real-Time Operating System for Robotics and Internet of Things
list.h
Go to the documentation of this file.
1 
4 #ifndef __LIST_H__
5 #define __LIST_H__
6 
7 #include <stddef.h>
8 
16 #define container_of(ptr, type, member) \
17  ((type *) ((void *) ptr - offsetof(type, member)))
18 
26 #define list_entry(ptr, type, member) container_of(ptr, type, member)
27 
35 #define list_first_entry(ptr, type, member) \
36  list_entry((ptr)->next, type, member)
37 
44 #define list_prev_entry(pos, member) \
45  list_entry((pos)->member.prev, typeof(*(pos)), member)
46 
53 #define list_next_entry(pos, member) \
54  list_entry((pos)->member.next, typeof(*(pos)), member)
55 
62 #define list_entry_is_head(pos, head, member) (&pos->member == (head))
63 
70 #define list_for_each(pos, head) \
71  for ((pos) = (head)->next; (pos) != (head); (pos) = (pos)->next)
72 
79 #define list_for_each_safe(pos, _next, head) \
80  for (pos = (head)->next, _next = (pos)->next; (pos) != (head); \
81  (pos) = _next, _next = (pos)->next)
82 
90 #define list_for_each_entry(pos, head, member) \
91  for (pos = list_first_entry(head, __typeof__(*pos), member); \
92  &pos->member != (head); pos = list_next_entry(pos, member))
93 
99 #define LIST_HEAD_INIT(name) \
100  { \
101  .prev = (&name), .next = (&name) \
102  }
103 
109 #define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name)
110 
111 struct list_head {
112  struct list_head *next, *prev;
113 };
114 
120 void INIT_LIST_HEAD(struct list_head *list);
121 
127 int list_empty(struct list_head *head);
128 
135 int list_is_last(const struct list_head *list, const struct list_head *head);
136 
143 void list_add(struct list_head *new, struct list_head *head);
144 
150 void list_del(struct list_head *entry);
151 
157 void list_del_init(struct list_head *entry);
158 
165 void list_move(struct list_head *list, struct list_head *new_head);
166 
167 #endif
void list_add(struct list_head *new, struct list_head *head)
Add new list member to the list.
Definition: list.c:31
int list_empty(struct list_head *head)
Check if the list is empty.
Definition: list.c:9
void list_move(struct list_head *list, struct list_head *new_head)
Move a list member from original list to another.
Definition: list.c:39
void list_del_init(struct list_head *entry)
Delete and force initialize a list member from its list.
Definition: list.c:25
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.
Definition: list.c:14
void list_del(struct list_head *entry)
Delete a list item from its list.
Definition: list.c:19
void INIT_LIST_HEAD(struct list_head *list)
Initialize the list head.
Definition: list.c:3
Definition: list.h:111