1 /*
2  * Copyright (C) 2015-2020 Alibaba Group Holding Limited
3  */
4 
5 #ifndef __UVOICE_LIST_H__
6 #define __UVOICE_LIST_H__
7 
8 
9 typedef struct uvoice_list {
10     struct uvoice_list *prev;
11     struct uvoice_list *next;
12 } uvoice_list_t;
13 
14 #define UVOICE_LIST_INIT(list)	\
15 	{&(list), &(list)}
16 
17 #define uvoice_list_for_each_entry(head, node, type, member)			\
18 	for (node = os_container_of((head)->next, type, member);				\
19 		&node->member != (head);										\
20 		node = os_container_of(node->member.next, type, member))
21 
22 #define uvoice_list_for_each_entry_safe(head, temp, node, type, member)	\
23 	for (node = os_container_of((head)->next, type, member),				\
24 		temp = (head)->next ? (head)->next->next : NULL;				\
25 		&node->member != (head);										\
26 		node = os_container_of(temp, type, member), temp = temp ? temp->next : NULL)
27 
uvoice_list_add(uvoice_list_t * node,uvoice_list_t * head)28 static inline void uvoice_list_add(uvoice_list_t *node, uvoice_list_t *head)
29 {
30 	uvoice_list_t *next = head->next;
31     node->next = next;
32     node->prev = head;
33 
34     head->next = node;
35     next->prev = node;
36 }
37 
uvoice_list_add_tail(uvoice_list_t * node,uvoice_list_t * head)38 static inline void uvoice_list_add_tail(uvoice_list_t *node, uvoice_list_t *head)
39 {
40 	uvoice_list_t *prev = head->prev;
41     node->next = head;
42     node->prev = prev;
43 
44     prev->next = node;
45     head->prev = node;
46 }
47 
uvoice_list_entry_count(uvoice_list_t * head)48 static inline int uvoice_list_entry_count(uvoice_list_t *head)
49 {
50 	uvoice_list_t *pos = head;
51 	int count = 0;
52 	while (pos->next != head) {
53 		pos = pos->next;
54 		count++;
55 	}
56 	return count;
57 }
58 
uvoice_list_empty(uvoice_list_t * head)59 static inline int uvoice_list_empty(uvoice_list_t *head)
60 {
61 	return head->next == head;
62 }
63 
uvoice_list_del(uvoice_list_t * node)64 static inline void uvoice_list_del(uvoice_list_t *node)
65 {
66     uvoice_list_t *prev = node->prev;
67     uvoice_list_t *next = node->next;
68 
69     prev->next = next;
70     next->prev = prev;
71 }
72 
uvoice_list_init(uvoice_list_t * head)73 static inline void uvoice_list_init(uvoice_list_t *head)
74 {
75 	head->next = head->prev = head;
76 }
77 
78 
79 #endif /* __UVOICE_LIST_H__ */
80 
81