码迷,mamicode.com
首页 > 系统相关 > 详细

linux 内核 中链表list

时间:2014-05-30 23:10:13      阅读:412      评论:0      收藏:0      [点我收藏+]

标签:c   a   ext   int   使用   数据   

这个结构从list.h 移到了types.h, 可见内核对循环链表的重视

include/linux/types.h中定义

struct list_head {
        struct list_head *next, *prev;
};

 

include/linux/list.h 中的宏

 

初始化 一个叫name的链表节点

#define LIST_HEAD_INIT(name) { &(name), &(name) }

#define LIST_HEAD(name) \
        struct list_head name = LIST_HEAD_INIT(name)

eg:

 

typdef struct  list_tag {

  struct list_head _list;

  int element;

  int other;

} xxx_list_t;

 

int main( void )

{

  xxx_list_t l = {

    ._list = LIST_HEAD_INIT( l._list ),

    .element = 1,

    .other = 2,

  };

}

 

 #define INIT_LIST_HEAD(ptr) do { \
 (ptr)->next = (ptr); (ptr)->prev = (ptr); \
 }

变成了

 static inline void INIT_LIST_HEAD(struct list_head *list)
 {  
   list->next = list;
   list->prev = list;
 }

 

不知还在哪里使用:

 #define LIST_HEAD(name) \ 
          struct list_head name = LIST_HEAD_INIT(name) 
定义一个头, 没有其他数据部分
xxxx_head
  next ------------------------>
  prev ------------------------>



#define list_entry(ptr, type, member) \ 
         container_of(ptr, type, member)
的作用是:

返回指针
---->struct {

   ptr----> list
    ...
}

即根据ptr 是那个结构struct 中的 那个成员可以得出这个包含它的结构体指针
这其中使用到了 typeof (根据一个变量返回一个 ‘类型‘)


 

 

 

 

linux 内核 中链表list,布布扣,bubuko.com

linux 内核 中链表list

标签:c   a   ext   int   使用   数据   

原文地址:http://www.cnblogs.com/kwingmei/p/3759965.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!