clib/dvb_ts_lib/shared/list.h

filter: Statementstmt 0.0% 0 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 0.0% 0 / 9 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« clib/dvb_ts_lib/dvbsnoop/crc32.c ↑ Summary clib/dvb_ts_lib/tables/parse_si.c »
1 #ifndef _LIST_H
2 #define _LIST_H 1
3  
4 /*
5 * Simple doubly linked list implementation.
6 * -- shameless stolen from the linux kernel sources
7 *
8 * Some of the internal functions ("__xxx") are useful when
9 * manipulating whole lists rather than single entries, as
10 * sometimes we already know the next/prev entries and we can
11 * generate better code by using them directly rather than
12 * using the generic single-entry routines.
13 */
14  
15 struct list_head {
16 struct list_head *next, *prev;
17 };
18  
19 #define LIST_HEAD_INIT(name) { &(name), &(name) }
20  
21 #define LIST_HEAD(name) \
22 struct list_head name = LIST_HEAD_INIT(name)
23  
24 #define INIT_LIST_HEAD(ptr) do { \
25 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
26 } while (0)
27  
28 /*
29 * Insert a item entry between two known consecutive entries.
30 *
31 * This is only for internal list manipulation where we know
32 * the prev/next entries already!
33 */
34 0 static __inline__ void __list_add(struct list_head * item,
35 struct list_head * prev,
36 struct list_head * next)
37 {
38 0 next->prev = item;
39 0 item->next = next;
40 0 item->prev = prev;
41 0 prev->next = item;
42 0 }
43  
44 /**
45 * list_add - add a item entry
46 * @item: item entry to be added
47 * @head: list head to add it after
48 *
49 * Insert a item entry after the specified head.
50 * This is good for implementing stacks.
51 */
52 static __inline__ void list_add(struct list_head *item, struct list_head *head)
53 {
54 __list_add(item, head, head->next);
55 }
56  
57 /**
58 * list_add_tail - add a item entry
59 * @item: item entry to be added
60 * @head: list head to add it before
61 *
62 * Insert a item entry before the specified head.
63 * This is useful for implementing queues.
64 */
65 0 static __inline__ void list_add_tail(struct list_head *item, struct list_head *head)
66 {
67 0 __list_add(item, head->prev, head);
68 0 }
69  
70 /*
71 * Delete a list entry by making the prev/next entries
72 * point to each other.
73 *
74 * This is only for internal list manipulation where we know
75 * the prev/next entries already!
76 */
77 static __inline__ void __list_del(struct list_head * prev,
78 struct list_head * next)
79 {
80 next->prev = prev;
81 prev->next = next;
82 }
83  
84 /**
85 * list_del - deletes entry from list.
86 * @entry: the element to delete from the list.
87 * Note: list_empty on entry does not return true after this, the entry is in an undefined state.
88 */
89 static __inline__ void list_del(struct list_head *entry)
90 {
91 __list_del(entry->prev, entry->next);
92 }
93  
94 /**
95 * list_del_init - deletes entry from list and reinitialize it.
96 * @entry: the element to delete from the list.
97 */
98 static __inline__ void list_del_init(struct list_head *entry)
99 {
100 __list_del(entry->prev, entry->next);
101 INIT_LIST_HEAD(entry);
102 }
103  
104 /**
105 * list_empty - tests whether a list is empty
106 * @head: the list to test.
107 */
108 static __inline__ int list_empty(struct list_head *head)
109 {
110 return head->next == head;
111 }
112  
113 /**
114 * list_splice - join two lists
115 * @list: the item list to add.
116 * @head: the place to add it in the first list.
117 */
118 static __inline__ void list_splice(struct list_head *list, struct list_head *head)
119 {
120 struct list_head *first = list->next;
121  
122 if (first != list) {
123 struct list_head *last = list->prev;
124 struct list_head *at = head->next;
125  
126 first->prev = head;
127 head->next = first;
128  
129 last->next = at;
130 at->prev = last;
131 }
132 }
133  
134 /**
135 * list_entry - get the struct for this entry
136 * @ptr: the &struct list_head pointer.
137 * @type: the type of the struct this is embedded in.
138 * @member: the name of the list_struct within the struct.
139 *
140 * e.g. struct psi_program *program = list_entry(item, struct psi_program, next);
141 */
142 #define list_entry(ptr, type, member) \
143 ((type *)((char *)(ptr)-(unsigned long)(&((type *)0)->member)))
144  
145 /**
146 * list_for_each - iterate over a list
147 * @pos: the &struct list_head to use as a loop counter.
148 * @head: the head for your list.
149 */
150 #define list_for_each(pos, head) \
151 for (pos = (head)->next; pos != (head); pos = pos->next)
152
153 /**
154 * list_for_each_safe - iterate over a list safe against removal of list entry
155 * @pos: the &struct list_head to use as a loop counter.
156 * @n: another &struct list_head to use as temporary storage
157 * @head: the head for your list.
158 */
159 #define list_for_each_safe(pos, n, head) \
160 for (pos = (head)->next, n = pos->next; pos != (head); \
161 pos = n, n = pos->next)
162  
163 /**
164 * list_for_each_prev - iterate over a list in reverse order
165 * @pos: the &struct list_head to use as a loop counter.
166 * @head: the head for your list.
167 */
168 #define list_for_each_prev(pos, head) \
169 for (pos = (head)->prev; pos != (head); pos = pos->prev)
170  
171 #endif /* _LIST_H */
« clib/dvb_ts_lib/dvbsnoop/crc32.c ↑ Summary clib/dvb_ts_lib/tables/parse_si.c »