|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
1、INIT_HLIST_HEAD【初始化头节点指针ptr】
& S. B; F" f4 g T# h0 ]7 d
9 t- }' e% z3 T; M& Q0 }! a) h/ s# T& e2 u: b
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)/ L: b0 Z7 k$ n* @
: @; P( B! z, ^( S: k2、INIT_HLIST_NODE【初始化hlist节点】
7 z2 r) Q" P2 |$ C1 E: X
% N: r7 X8 f7 y( P% w7 e' v: [* P1 Q1 K( [ P: c" E7 e
- static __INLINE__ void INIT_HLIST_NODE(struct hlist_node *h)
- {
- h->next =NULL;
- h->pprev =NULL;
- }2 |, O% J* ]# y
- n2 ^$ N9 }, ]3 t9 K0 z2 H# a
# {2 ]3 A$ t: J) d: R8 [$ x6 R
3、hlist_unhashed【判断h->pprev是否为空,是返回1,否返回0】4 v: d& t; y" d& ]' u
9 Z) i0 [2 e( `# \) h% P
) {( h: j0 {3 g, P# [$ n, o, B
- static __INLINE__ int hlist_unhashed(const struct hlist_node *h)
- {
- return !h->pprev;
- }, V/ {& h; }# q ?( s8 {! l
$ f9 o# q; _) q: C# g0 Y
5 G; g7 Y8 w+ p1 C, t4、hlist_empty【判断hlist是否为空,是返回1,否返回0】1 G. f1 g5 @2 L* w8 X
# L; _& x, b4 q) e
+ k: R5 R9 y2 X0 S0 `$ v4 ]0 k- static __INLINE__ int hlist_empty(const struct hlist_head *h)
- {
- return !h->first;
- }
/ p! f1 g1 z) i : M0 V: m/ i4 W( I
" W) l/ I5 `" N& Y5、__hlist_del【删除结点n】
' L$ k2 [7 Z' J3 E5 i; ?/ X
+ C. j7 S! B4 j2 ^# O2 d9 B& L# D a
2 ]$ j: f2 @, a7 G- static __INLINE__ void __hlist_del(struct hlist_node*n)
- {
- struct hlist_node *next = n->next;
- struct hlist_node **pprev = n->pprev;
- *pprev = next;
- if (next)
- {
- next->pprev = pprev;
- }
- }- S8 ?5 K1 z$ Q' m; L8 G8 V
* r) n3 ~7 N' q& v( {3 H& _7 `! S) h
# r; m. _; \% A7 ~4 K+ Q6 y6、hlist_del【删除结点n,将结点next、pprev分别指向LIST_POISON1、LIST_POISON2。这样设置是为了保证不在链表中的结点项不能被访问】
' W# C& m: M7 j: b4 q- {6 @: l% [. |9 l5 ^
- p# R: f/ y. @- W) M3 h- static __INLINE__ void hlist_del(struct hlist_node *n)
- {
- __hlist_del(n);
- n->next =LIST_POISON1;
- n->pprev =LIST_POISON2;
- }
6 g& N3 K% J$ {6 O3 W
: K4 `- ~' o ^# n! @5 G- l4 w
5 e9 U/ ] E$ v$ ~4 w7、hlist_del_init【先判断结点是否为空,不为空删除,再初始化节点】
2 S# G0 Q2 P4 R
& i# M. i6 o1 ?& P3 O5 W. g1 e/ f" q# W F9 ?5 H! c, T) N) B
- static __INLINE__ void hlist_del_init(struct hlist_node *n)
- {
- if(!hlist_unhashed(n))
- {
- __hlist_del(n);
- INIT_HLIST_NODE(n);
- }
- }' n7 L4 e9 `4 ?* c" ^
4 s+ ]9 U5 p* N, ]# f7 X
, j! C; |% S# j! B5 H" P8、hlist_add_head【增加结点n到h表头】
) G! n* F7 H- P) m: ]
1 l, x4 i. t, v* }& ]
( ]' \8 q& |8 q, E- static __INLINE__ void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
- {
- struct hlist_node *first = h->first;
- n->next =first;
- if (first)
- {
- first->pprev = &n->next;
- }
- h->first =n;
- n->pprev =&h->first;
- }<span style="font-family: Arial, Helvetica, sans-serif; background-color: rgb(255, 255, 255);"> </span>" K6 Y: x1 ^3 _' O3 b
* L8 k0 X) V6 X# @" ^5 s* f# N% r, w g1 F- Q* p
9、hlist_add_before【增加结点n到结点next之前】
* s; c4 C. p2 T0 v( U# d' v* t4 _* d
: R* M+ v$ F0 P8 L
- /* next must be != NULL */
- static __INLINE__ void hlist_add_before(struct hlist_node *n,
- struct hlist_node *next)
- {
- n->pprev =next->pprev;
- n->next = next;
- next->pprev= &n->next;
- *(n->pprev)= n;
- }
' G- V1 G7 L4 l9 C6 Y
+ g# r2 m* d: g$ B# |! v 6 G$ }. H$ x) |( R0 e# X4 B: q9 ]
10、hlist_add_after【增加结点n到结点next之后】
0 D2 d% \; p5 n' p4 K; z: n
8 g0 } D/ ?; m6 j f1 r* U
$ y) P' a/ T/ D- static __INLINE__ void hlist_add_after(struct hlist_node *n,
- struct hlist_node *next)
- {
- next->next= n->next;
- n->next =next;
- next->pprev= &n->next;
- if(next->next)
- {
- next->next->pprev =&next->next;
- }
- }
2 f7 J( K! `7 i: W5 @& u* R0 @ ; U- l7 J" C+ [# M6 F" \- d
5 X& c* P, [3 y z11、hlist_move_list【头结点new接管头结点old的所有节点,并初始化old】
6 ^' ?6 C: A" _0 W5 I
; i) c/ s! F0 {# I' H+ d" R6 N! w0 T7 N. u$ }! c0 G
- static __INLINE__ void hlist_move_list(struct hlist_head *old,
- struct hlist_head *new)
- {
- new->first= old->first;
- if(new->first)
- {
- new->first->pprev = &new->first;
- }
- old->first= NULL;
- }7 l- d2 q# W- M* S4 M
* J/ G4 z9 Q( v0 ~
1 T; [ R3 e; E6 E4 x
12、hlist_entry【已知某一个成员变量的名字、指针和结构体类型的情况下,计算结构体的指针,也就是计算结构体的起始地址】
0 F) R* _8 `, W
/ T# Z0 Q% D4 D. `; l9 A8 Z' I) d; \ G% u$ K
#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
* D" w& E$ h. H$ a- {$ [) [" Z v+ Z/ F9 w& |/ a
& H4 }3 g6 M' [6 U4 W13、hlist_for_each【遍历hlist链表】
1 V+ C l; x5 b' B; V' |
4 G! ^9 A* \- R+ L0 u1 Z3 z7 {( ]8 C+ S+ Q! A' i$ t& _
- #define hlist_for_each(pos, head) \
- for (pos =(head)->first; pos ; \
- pos =pos->next)
# c, W1 K1 ~9 \5 H" f+ y' s& l
, _& V) h. x' w0 Y. d) k, K 3 p: @4 z0 U" S* c% ^# w
14、 hlist_for_each_safe【遍历hlist链表,一般在删除结点使用】
1 M( K, K7 Z n3 i" c* c5 i9 E' ^6 n0 `. ~$ ?( V% c! h# l
6 b p7 y# F2 D k. n
- #define hlist_for_each_safe(pos, n, head) \
- for (pos =(head)->first; pos && ({ n = pos->next; 1; }); \
- pos = n)
4 ]0 u6 ?* O8 a+ h& I( B* f
5 {( x X( v3 N' G$ E
' n) y: M) Y ~15、hlist_for_each_entry【遍历找typeof(*tpos)的结构体类型入口地址】5 ]6 r, q% s. v, t4 Y9 q* ~
+ ~4 I$ |- k! ^
& G2 F" \$ F3 w1 C; I- #define hlist_for_each_entry(tpos, pos, head,member) \
- for (pos =(head)->first; \
- pos&& ({ prefetch(pos->next); 1;}) && \
- ({ tpos =hlist_entry(pos, typeof(*tpos), member); 1;}); \
- pos =pos->next); N$ q# ]' m) O6 V+ |
/ z3 _ i3 O0 I8 z" y% p16、hlist_for_each_entry_continue【从结点pos下一个遍历找typeof(*tpos)的结构体类型入口地址】
2 F$ W( d1 F: Z% S& q
" o4 M8 G8 ^! u/ Z) Q+ ]( O
' u0 h! k7 |$ M# O9 }0 ]* c: i5 a- #define hlist_for_each_entry_continue(tpos, pos,member) \
- for (pos =(pos)->next; \
- pos&& ({ prefetch(pos->next); 1;}) && \
- ({ tpos =hlist_entry(pos, typeof(*tpos), member); 1;}); \
- pos =pos->next)
! t) `% H6 G$ M n2 d + u1 g5 ?" Z1 k( u4 W, b
- h' m+ q! C& x5 C) f& Z
17、hlist_for_each_entry_from【从节点pos开始遍历找typeof(*tpos)的结构体类型入口地址】. h. e$ O2 D' v
( A2 K3 w6 S: `/ z
" v% F8 W/ I# C! x
- #define hlist_for_each_entry_from(tpos, pos,member) \
- for (; pos&& ({ prefetch(pos->next); 1;}) && \
- ({ tpos =hlist_entry(pos, typeof(*tpos), member); 1;}); \
- pos =pos->next)
0 o1 w; n# K8 b. o% n& A5 k9 s/ s
/ g: F* F% _9 W$ U3 _4 r. `0 M h: @
+ m- T; t' ^1 ~6 D0 B5 `18、hlist_for_each_entry_safe【从头节点head开始遍历找typeof(*tpos)的结构体类型入口地址】
8 w. E0 V+ z1 y% k: M' S( y3 I
+ Z, r8 O0 o! K9 |& u
. `* |& x7 [) l; X+ b1 E- #define hlist_for_each_entry_safe(tpos, pos, n, head,member) \
- for (pos =(head)->first; \
- pos&& ({ n = pos->next; 1; }) && \
- ({ tpos =hlist_entry(pos, typeof(*tpos), member); 1;}); \
- pos = n)+ s( }8 i8 u6 v. L& Y
; {2 X3 q' H$ U9 J! Z
3 i$ B, W0 [: {
. p" q( b6 s" u/ B
1 m. Z% W; Z) L- }+ m$ y0 ?3 u$ s
& @) q( ~- a3 |* z& h c) f1 R( H' S$ f3 Q# M7 z
+ Y3 x! S+ L! m' {% Y5 `1 ~
3 n: f7 G- X# v# v5 t3 ~1 j( ^
: K% T: x4 C. n0 o2 f |
|