你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux内核链表的研究与应用

[日期:2013-01-17] 来源:CSDN  作者:tigerjb [字体:大 中 小]

四.链表的其他操作
1.结点的替换
1>function:
结点的替换是将old的结点替换成new

2>linux内核提供了两个函数接口:
static inline void list_replace(struct list_head *old,struct list_head *new)
static inline void list_replace_init(struct list_head *old,struct list_head *new)

3> list_replace()函数的实现:
static inline void list_replace(struct list_head *old, struct list_head *new)
{
    new->next = old->next;
    new->next->prev = new;
    new->prev = old->prev;
    new->prev->next = new;
}
list_repleace()函数只是改变new和old的指针关系,然而old指针并没有释放。

4> list_replace_init()函数的实现:
static inline void list_replace_init(struct list_head *old, struct list_head *new)
{
    list_replace(old, new);
    INIT_LIST_HEAD(old);
}
List_repleace_init首先调用list_replace改变new和old的指针关系,然后调用INIT_LIST_HEAD(old)将old结点初始化空结点。

2结点的移动
1>function:
将一个结点从一个链表中删除,添加到另一个链表中。

2>linxu内核链表中提供了两个接口
static inline void list_move(struct list_head *list, struct list_head *head)
static inline  void list_move_tail(struct list_head *list, struct list_head *head)
前者添加的时候使用的是头插法,后者使用的是尾插法

3> list_move函数实现
static inline void list_move(struct list_head *list, struct list_head *head)
 {
        __list_del_entry(list);
        list_add(list, head);
 }
List_move函数调用__list_del_entry()函数将lis结点删除,然后调用list_add()函数将其插入到head结点中(使用头插法)

4>list_move_tail函数实现
static inline void list_move_tail(struct list_head *list, struct list_head *head)
 {
        __list_del_entry(list);
        list_add_tail(list, head);
 }
list_move_tail()函数调用_list_del_entry函数将list结点删除,然后调用list_add_tail函数将list结点插入到head结点中(使用尾插法)

linux
相关资讯       Linux内核链表  内核链表  Linux链表 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款