TuyaOS
tuya_hlist.h
浏览该文件的文档.
1
10#ifndef __TUYA_HLIST_H__
11#define __TUYA_HLIST_H__
12
13#include "tuya_cloud_types.h"
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
23typedef struct hlist_node {
24 struct hlist_node *next,**pprev;
26
31typedef struct hlist_head{
32 struct hlist_node *first;
34
39#define HLIST_HEAD_INIT { .first = NULL}
40
45#define HLIST_HEAD(name) HLIST_HEAD name = {.first = NULL}
46
51#define INIT_HLIST_HEAD(ptr) ((ptr->first)=NULL)
52
57#define HLIST_ENTRY(ptr, type, member) CNTR_OF(ptr,type,member)
58
63#define HLIST_FOR_EACH_ENTRY(tpos, type, pos, head, member) \
64 for (pos = (head)->first; \
65 pos && (tpos = HLIST_ENTRY(pos, type, member), 1); \
66 pos = pos->next)
67
72#define HLIST_FOR_EACH_ENTRY_CURR(tpos, type, pos, curr, member) \
73 for (pos = (curr)->next; \
74 pos && (tpos = HLIST_ENTRY(pos, type, member), 1); \
75 pos = pos->next)
76
81#define HLIST_FOR_EACH_ENTRY_SAFE(tpos, type, pos, n, head, member) \
82 for (pos = (head)->first; \
83 pos && (n = pos->next, 1) && \
84 (tpos = HLIST_ENTRY(pos, type, member), 1); \
85 pos = n)
86
91#define HLIST_FOR_EACH(pos, head) \
92 for (pos = (head)->first; pos ; \
93 pos = pos->next)
94
99#define HLIST_FOR_EACH_SAFE(pos, n, head) \
100 for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
101 pos = n)
102
103
110STATIC INLINE VOID tuya_init_hlist_node(INOUT HLIST_NODE *h)
111{
112 h->next = NULL;
113 h->pprev = NULL;
114}
115
122STATIC INLINE INT_T tuya_hlist_empty(IN CONST HLIST_HEAD *h)
123{
124 return !h->first;
125}
126
133STATIC INLINE INT_T tuya_hlist_unhashed(IN CONST HLIST_NODE *h)
134{
135 return !h->pprev;
136}
137
146STATIC INLINE VOID __tuya_hlist_del(INOUT HLIST_NODE *n)
147{
148 HLIST_NODE *next = n->next;
149 HLIST_NODE **pprev = n->pprev;
150 *pprev = next;
151 if (next)
152 next->pprev = pprev;
153}
154
161STATIC INLINE VOID tuya_hlist_del(INOUT HLIST_NODE *n)
162{
163 __tuya_hlist_del(n);
164 // n->next = NULL;
165 // n->pprev = NULL;
166}
167
174STATIC INLINE VOID tuya_hlist_del_init(INOUT HLIST_NODE *n)
175{
176 if (!tuya_hlist_unhashed(n)) {
177 __tuya_hlist_del(n);
178 tuya_init_hlist_node(n);
179 }
180}
181
189STATIC INLINE VOID tuya_hlist_add_head(INOUT HLIST_NODE *n, INOUT HLIST_HEAD *h)
190{
191 struct hlist_node *first = h->first;
192 n->next = first;
193 if (first)
194 first->pprev = &n->next;
195 h->first = n;
196 n->pprev = &h->first;
197}
198
208STATIC INLINE VOID tuya_hlist_add_before(INOUT HLIST_NODE *n, INOUT HLIST_NODE *next)
209{
210 n->pprev = next->pprev;
211 n->next = next;
212 next->pprev = &n->next;
213 *(n->pprev) = n;
214}
215
225STATIC INLINE VOID tuya_hlist_add_after(INOUT HLIST_NODE *n, INOUT HLIST_NODE *next)
226{
227 next->next = n->next;
228 n->next = next;
229 next->pprev = &n->next;
230
231 if(next->next)
232 next->next->pprev = &next->next;
233}
234
235#ifdef __cplusplus
236}
237#endif /* __cplusplus */
238#endif
hash list head
Definition: tuya_hlist.h:31
hash list node
Definition: tuya_hlist.h:23
struct hlist_node HLIST_NODE
hash list node
#define HLIST_HEAD(name)
hash list head define and initialization
Definition: tuya_hlist.h:45