网站做竞价对seo有影响吗,自学python需要的软件,客户网站建设公司,怎么学做网站PHP内核链表
1 list_head 结构
为了使用链表机制#xff0c;驱动程序需要包含linux/types.h头文件#xff0c;该文件定义了如下结构体实现双向链#xff1a;
struct list_head {struct list_head *next, *prev;
};2 链表的初始化
2.1 链表宏定义和初始化
可使用以…内核链表
1 list_head 结构
为了使用链表机制驱动程序需要包含linux/types.h头文件该文件定义了如下结构体实现双向链
struct list_head {struct list_head *next, *prev;
};2 链表的初始化
2.1 链表宏定义和初始化
可使用以下宏定义并初始化一个链表头部list_headlist_head 不包含数据部分。LIST_HEAD_INIT将链表头的 next 和 prev 指针都指向链表头部从而形成一个循环结构和下面介绍的INIT_LIST_HEAD函数一样。
#define LIST_HEAD_INIT(name) { (name), (name) }#define LIST_HEAD(name) \struct list_head name LIST_HEAD_INIT(name)2.2 链表的初始化
INIT_LIST_HEAD 是一个用于初始化链表头的函数它将链表头的 next 和 prev 指针都指向自己从而形成一个循环结构。
static inline void INIT_LIST_HEAD(struct list_head *list)
{WRITE_ONCE(list-next, list);WRITE_ONCE(list-prev, list);
}如下图所示链表头的 next 和 prev 指针都指向自己。
3 list_add
在链表的头部添加新链表项以下是实现
static inline void list_add(struct list_head *new, struct list_head *head)
{__list_add(new, head, head-next);
}static inline void __list_add(struct list_head *new,struct list_head *prev,struct list_head *next)
{if (!__list_add_valid(new, prev, next))return;next-prev new;new-next next;new-prev prev;WRITE_ONCE(prev-next, new);
}以下为添加示意图可以看出后添加节点放在链表的头部先添加节点靠后先进后出后进先出类似栈结构。
4 list_add_tail
在链表的尾部添加新链表项以下是实现 static inline void list_add_tail(struct list_head *new, struct list_head *head)
{__list_add(new, head-prev, head);
}static inline void __list_add(struct list_head *new,struct list_head *prev,struct list_head *next)
{if (!__list_add_valid(new, prev, next))return;next-prev new;new-next next;new-prev prev;WRITE_ONCE(prev-next, new);
}以下为添加示意图可以看出新添加节点放在链表的尾部后添加节点靠先进先出后进后出类似FIFO结构。
5 遍历节点
5.1 list_entry
list_entry 宏通过调用 container_of 宏从链表节点指针获取包含该节点的结构体指针。
/*** list_entry - get the struct for this entry* ptr: 指向 struct list_head 的指针。* type: 包含该节点的结构体类型。* member: 结构体中的 list_struct 名称。*/
#define list_entry(ptr, type, member) \container_of(ptr, type, member)5.2 list_for_each
list_for_each 从链表的头部往后依次遍历next方向。
/*** list_for_each - iterate over a list* pos: the struct list_head to use as a loop cursor.* head: the head for your list.*/
#define list_for_each(pos, head) \for (pos (head)-next; !list_is_head(pos, (head)); pos pos-next)5.3 list_for_each_entry
通过for循环依次遍历链表中的每个节点next方向遍历每个节点的宿主为pos。
/*** list_for_each_entry - iterate over list of given type* pos: the type * to use as a loop cursor.* head: the head for your list.* member: the name of the list_head within the struct.*/
#define list_for_each_entry(pos, head, member) \for (pos list_first_entry(head, typeof(*pos), member); \!list_entry_is_head(pos, head, member); \pos list_next_entry(pos, member))a. list_first_entry 宏:
#define list_first_entry(ptr, type, member) \container_of((ptr)-next, type, member)list_first_entry 宏用于获取链表的第一个节点的结构体指针。通过 (ptr)-next 获取到链表头部之后的第一个节点的指针然后通过 container_of 宏获取包含该节点的整个结构体指针。
b. list_entry_is_head 宏:
#define list_entry_is_head(pos, head, member) \((pos)-member (head))list_entry_is_head 宏用于检查当前节点是否是链表的头部。比较 pos-member 是否等于 head如果相等则说明当前节点是链表的头部即遍历结束。
c. list_next_entry 宏:
#define list_next_entry(pos, member) \list_entry((pos)-member.next, typeof(*(pos)), member)list_next_entry 宏用于获取下一个节点的结构体指针。通过 (pos)-member.next 获取到当前节点的下一个节点的指针然后通过 list_entry 宏获取包含该节点的整个结构体指针。
5.4 list_for_each_prev
通过for循环依次遍历链表中的每个节点与list_for_each_entry不同的是list_for_each_prev按照pre方向遍历每个节点的宿主为pos。
/*** list_for_each_prev - iterate over a list backwards* pos: the struct list_head to use as a loop cursor.* head: the head for your list.*/
#define list_for_each_prev(pos, head) \for (pos (head)-prev; !list_is_head(pos, (head)); pos pos-prev)5.5 删除链表
list_del 删除列表中的给定项
/*** list_del - deletes entry from list.* entry: the element to delete from the list.* Note: list_empty() on entry does not return true after this, the entry is* in an undefined state.*/
static inline void list_del(struct list_head *entry)
{__list_del_entry(entry);entry-next LIST_POISON1;entry-prev LIST_POISON2;
}list_del_init 删除列表中的给定项如果删除后的链表可能被插入新的链表中应该使用list_del_init它会初始化链表的指针。
/*** list_del_init - deletes entry from list and reinitialize it.* entry: the element to delete from the list.*/
static inline void list_del_init(struct list_head *entry)
{__list_del_entry(entry);INIT_LIST_HEAD(entry);
}
文章转载自: http://www.morning.tndhm.cn.gov.cn.tndhm.cn http://www.morning.lfxcj.cn.gov.cn.lfxcj.cn http://www.morning.nrwr.cn.gov.cn.nrwr.cn http://www.morning.blbys.cn.gov.cn.blbys.cn http://www.morning.rbnp.cn.gov.cn.rbnp.cn http://www.morning.xrrbj.cn.gov.cn.xrrbj.cn http://www.morning.bbjw.cn.gov.cn.bbjw.cn http://www.morning.blxlf.cn.gov.cn.blxlf.cn http://www.morning.zlxkp.cn.gov.cn.zlxkp.cn http://www.morning.qxnns.cn.gov.cn.qxnns.cn http://www.morning.xfyjn.cn.gov.cn.xfyjn.cn http://www.morning.kqzxk.cn.gov.cn.kqzxk.cn http://www.morning.mxlmn.cn.gov.cn.mxlmn.cn http://www.morning.rmtxp.cn.gov.cn.rmtxp.cn http://www.morning.beeice.com.gov.cn.beeice.com http://www.morning.bpds.cn.gov.cn.bpds.cn http://www.morning.lgxzj.cn.gov.cn.lgxzj.cn http://www.morning.mzpd.cn.gov.cn.mzpd.cn http://www.morning.ggfdq.cn.gov.cn.ggfdq.cn http://www.morning.zpjhh.cn.gov.cn.zpjhh.cn http://www.morning.brbmf.cn.gov.cn.brbmf.cn http://www.morning.gydsg.cn.gov.cn.gydsg.cn http://www.morning.lrplh.cn.gov.cn.lrplh.cn http://www.morning.sglcg.cn.gov.cn.sglcg.cn http://www.morning.dpnhs.cn.gov.cn.dpnhs.cn http://www.morning.rhfbl.cn.gov.cn.rhfbl.cn http://www.morning.nlqgb.cn.gov.cn.nlqgb.cn http://www.morning.fddfn.cn.gov.cn.fddfn.cn http://www.morning.rfbpq.cn.gov.cn.rfbpq.cn http://www.morning.qgmbx.cn.gov.cn.qgmbx.cn http://www.morning.gccdr.cn.gov.cn.gccdr.cn http://www.morning.tlpgp.cn.gov.cn.tlpgp.cn http://www.morning.pzwfw.cn.gov.cn.pzwfw.cn http://www.morning.mnjyf.cn.gov.cn.mnjyf.cn http://www.morning.wjrtg.cn.gov.cn.wjrtg.cn http://www.morning.tkryt.cn.gov.cn.tkryt.cn http://www.morning.npbgj.cn.gov.cn.npbgj.cn http://www.morning.wfzlt.cn.gov.cn.wfzlt.cn http://www.morning.hxsdh.cn.gov.cn.hxsdh.cn http://www.morning.qqhersx.com.gov.cn.qqhersx.com http://www.morning.wnnlr.cn.gov.cn.wnnlr.cn http://www.morning.zpnfc.cn.gov.cn.zpnfc.cn http://www.morning.mrnnb.cn.gov.cn.mrnnb.cn http://www.morning.hxhrg.cn.gov.cn.hxhrg.cn http://www.morning.nwynx.cn.gov.cn.nwynx.cn http://www.morning.plflq.cn.gov.cn.plflq.cn http://www.morning.rhsr.cn.gov.cn.rhsr.cn http://www.morning.syynx.cn.gov.cn.syynx.cn http://www.morning.tllhz.cn.gov.cn.tllhz.cn http://www.morning.cfhwn.cn.gov.cn.cfhwn.cn http://www.morning.pzbjy.cn.gov.cn.pzbjy.cn http://www.morning.qpsxz.cn.gov.cn.qpsxz.cn http://www.morning.mxgpp.cn.gov.cn.mxgpp.cn http://www.morning.zcqgf.cn.gov.cn.zcqgf.cn http://www.morning.bmtyn.cn.gov.cn.bmtyn.cn http://www.morning.mjdbd.cn.gov.cn.mjdbd.cn http://www.morning.pgmyn.cn.gov.cn.pgmyn.cn http://www.morning.qbxdt.cn.gov.cn.qbxdt.cn http://www.morning.dbrnl.cn.gov.cn.dbrnl.cn http://www.morning.srtw.cn.gov.cn.srtw.cn http://www.morning.qscsy.cn.gov.cn.qscsy.cn http://www.morning.hotlads.com.gov.cn.hotlads.com http://www.morning.lsfbb.cn.gov.cn.lsfbb.cn http://www.morning.kflzy.cn.gov.cn.kflzy.cn http://www.morning.fhcwm.cn.gov.cn.fhcwm.cn http://www.morning.ysskn.cn.gov.cn.ysskn.cn http://www.morning.llqky.cn.gov.cn.llqky.cn http://www.morning.fmznd.cn.gov.cn.fmznd.cn http://www.morning.mlfmj.cn.gov.cn.mlfmj.cn http://www.morning.mhmsn.cn.gov.cn.mhmsn.cn http://www.morning.jqmmf.cn.gov.cn.jqmmf.cn http://www.morning.nlgmr.cn.gov.cn.nlgmr.cn http://www.morning.qqbw.cn.gov.cn.qqbw.cn http://www.morning.tbjtm.cn.gov.cn.tbjtm.cn http://www.morning.bswxt.cn.gov.cn.bswxt.cn http://www.morning.nflpk.cn.gov.cn.nflpk.cn http://www.morning.qwgct.cn.gov.cn.qwgct.cn http://www.morning.frzdt.cn.gov.cn.frzdt.cn http://www.morning.xsbhg.cn.gov.cn.xsbhg.cn http://www.morning.stsnf.cn.gov.cn.stsnf.cn