TuyaOS
tuya_list.h
浏览该文件的文档.
1
10#ifndef __TUYA_LIST_H__
11#define __TUYA_LIST_H__
12
13#include "tuya_cloud_types.h"
14
15
16#ifdef __cplusplus
17extern "C" {
18#endif
19
24typedef struct tuya_list_head
25{
26 struct tuya_list_head *next, *prev;
28
33#define LIST_HEAD_INIT(name) { &(name), &(name) }
34#define LIST_HEAD(name) \
35LIST_HEAD name = LIST_HEAD_INIT(name)
36
41#define INIT_LIST_HEAD(ptr) do { \
42(ptr)->next = (ptr); (ptr)->prev = (ptr); \
43} while (0)
44
49#define NEW_LIST_NODE(type, node) \
50{\
51 node = (type *)tal_malloc(sizeof(type));\
52}
53
58#define FREE_LIST(type, p, list_name)\
59{\
60 type *posnode;\
61 while(!tuya_list_empty(&(p)->list_name)) {\
62 posnode = tuya_list_entry((&(p)->list_name)->next, type, list_name);\
63 tuya_list_del((&(p)->list_name)->next);\
64 tal_free(posnode);\
65 }\
66}
67
72#define GetFirstNode(type,p,list_name,pGetNode)\
73{\
74 pGetNode = NULL;\
75 while(!tuya_list_empty(&(p)->list_name)){\
76 pGetNode = tuya_list_entry((&(p)->list_name)->next, type, list_name);\
77 break;\
78 }\
79}
80
86#define DeleteNodeAndFree(pDelNode,list_name)\
87{\
88 tuya_list_del(&(pDelNode->list_name));\
89 tal_free(pDelNode);\
90}
91
96#define DeleteNode(pDelNode,list_name)\
97{\
98 tuya_list_del(&(pDelNode->list_name));\
99}
100
105#define FreeNode(pDelNode)\
106{\
107 tal_free(pDelNode);\
108}
109
114#define tuya_list_entry(ptr, type, member) \
115((type *)((char *)(ptr)-(size_t)(&((type *)0)->member)))
116
121#define tuya_list_for_each(pos, head) \
122for (pos = (head)->next; (pos != NULL) && (pos != (head)); pos = pos->next)
123
128#define tuya_list_for_each_safe(p, n, head) \
129for (p = (head)->next; n = p->next, p != (head); p = n)
130
137INT_T tuya_list_empty(IN CONST P_LIST_HEAD pHead);
138
146VOID tuya_list_add(IN CONST P_LIST_HEAD pNew, IN CONST P_LIST_HEAD pHead);
147
155VOID tuya_list_add_tail(IN CONST P_LIST_HEAD pNew, IN CONST P_LIST_HEAD pHead);
156
164VOID tuya_list_splice(IN CONST P_LIST_HEAD pList, IN CONST P_LIST_HEAD pHead);
165
172VOID tuya_list_del(IN CONST P_LIST_HEAD pEntry);
173
180VOID tuya_list_del_init(IN CONST P_LIST_HEAD pEntry);
181
182#ifdef __cplusplus
183}
184#endif /* __cplusplus */
185
186#endif
bidirection list head
Definition: tuya_list.h:25
INT_T tuya_list_empty(const P_LIST_HEAD pHead)
check if the bidirection list is empty
struct tuya_list_head LIST_HEAD
bidirection list head
void tuya_list_del(const P_LIST_HEAD pEntry)
remove a list node from bidirection list
void tuya_list_add_tail(const P_LIST_HEAD pNew, const P_LIST_HEAD pHead)
add new list node to the tail of the bidirection list
void tuya_list_splice(const P_LIST_HEAD pList, const P_LIST_HEAD pHead)
splice two dibrection list
void tuya_list_add(const P_LIST_HEAD pNew, const P_LIST_HEAD pHead)
add new list node into bidirection list
void tuya_list_del_init(const P_LIST_HEAD pEntry)
remove a list node from bidirection list and initialize it